Files
2026-09-21 15:32:12 +08:00

66 lines
1.5 KiB
Vue

<template>
<div class="demo">
<p class="tip">
<span class="anchor" v-popup="'这是一段纯文本提示'">悬停看文本提示</span>
</p>
<p class="tip">
<span class="anchor" v-popup="imageConfig">悬停看图片</span>
</p>
<p class="tip">
<span class="anchor" v-popup="htmlConfig">悬停看 HTML</span>
</p>
<p class="note" v-text="'Popup 是全局唯一的浮层挂载点,页面上只需放置一次。'" />
<popup />
</div>
</template>
<script lang="ts" setup>
import { Popup, PopupType, VPopup } from "timi-web";
/** 演示用图片:内联 SVG,避免依赖外部图床。 */
const image = `data:image/svg+xml;utf8,${encodeURIComponent(
`<svg xmlns="http://www.w3.org/2000/svg" width="200" height="90">` +
`<rect width="100%" height="100%" fill="#3451b2"/>` +
`<text x="50%" y="50%" font-size="16" fill="#fff" text-anchor="middle" ` +
`dominant-baseline="central">Popup 图片</text></svg>`
)}`;
/**
* `v-popup` 的值可以是字符串(按纯文本展示),
* 也可以是包含 type / value 的配置对象。
*/
const imageConfig = {
type: PopupType.IMG,
value: image
};
const htmlConfig = {
type: PopupType.HTML,
value: "<b>加粗</b>与<i>斜体</i>都能渲染"
};
</script>
<style lang="less" scoped>
.demo {
.tip {
margin: 0 0 .75rem;
}
.anchor {
cursor: help;
border-bottom: 1px dashed var(--vp-c-brand-1);
color: var(--vp-c-brand-1);
}
.note {
margin: 1rem 0 0;
font-size: .75rem;
color: var(--vp-c-text-2);
}
}
</style>