文档地址
atomiks.github.io/tippyjs/
效果预览
demo.webwlx.cn/#/tips
封装为指令
import tippy from 'tippy.js';
import 'tippy.js/dist/tippy.css';
import 'tippy.js/themes/light.css';
import 'tippy.js/themes/light-border.css';
import 'tippy.js/animations/scale.css';
import 'tippy.js/animations/scale-extreme.css';
function createdTips(el, binding) {
if (!binding.value.content) {
removeTips(el);
return false;
}
el.classList.add('data-tips');
let defaultConfigProps = {
animation: 'scale-extreme',
};
tippy(el, Object.assign(defaultConfigProps, binding.value));
}
function removeTips(el) {
el._tippy ? el._tippy.destroy() : '';
el.classList.remove('data-tips');
}
const tips = {
mounted(el, binding) {
createdTips(el, binding);
},
updated(el, binding) {
createdTips(el, binding);
},
unmounted(el) {
removeTips(el);
},
};
export default tips;
挂载指令
单组件引入
<script setup>
import tips from './tips.js';
const vTips = tips;
</script>
<script>
export default {
directives:{tips}
}
</script>
全局引入main.js
import tips from './tips.js';
app.directive('tips', tips);
import tips from './tips.js';
Vue.directive('tips', tips);
使用指令
<n-button v-tips="{ content: '这是一个默认提示' }">Default</n-button>
<n-button v-tips="{ content: '这是一个默认提示', theme: 'light' }" type="tertiary"> Tertiary </n-button>
<n-button v-tips="{ content: '这是一个默认提示', theme: 'light-border' }" type="primary"> Primary </n-button>