workflow(sfc-playground): make warnings dismissable

This commit is contained in:
Evan You 2021-03-29 16:06:14 -04:00
parent 7ab519cc96
commit 4d9f9fdf9d

View File

@ -1,16 +1,23 @@
<template> <template>
<Transition name="fade"> <Transition name="fade">
<pre v-if="err || warn" <pre v-if="!dismissed && (err || warn)"
class="msg" class="msg"
:class="err ? 'err' : 'warn'">{{ formatMessage(err || warn) }}</pre> :class="err ? 'err' : 'warn'"
@click="dismissed = true">{{ formatMessage(err || warn) }}</pre>
</Transition> </Transition>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { defineProps } from 'vue' import { defineProps, ref, watch } from 'vue'
import type { CompilerError } from '@vue/compiler-sfc' import type { CompilerError } from '@vue/compiler-sfc'
defineProps(['err', 'warn']) const props = defineProps(['err', 'warn'])
const dismissed = ref(false)
watch(() => [props.err, props.warn], () => {
dismissed.value = false
})
function formatMessage(err: string | Error): string { function formatMessage(err: string | Error): string {
if (typeof err === 'string') { if (typeof err === 'string') {