代码拉取完成,页面将自动刷新
项目网址: https://gitee.com/linuxmail/vue3-plugin-demo
vue3 插件 演示
包括
src/vue3-plugin-demo
./vue3-plugin-demo 就是插件目录
import { createApp } from "vue"
import vue3PluginDemo from "./vue3-plugin-demo/plugin"
import APP from "./app.vue"
const app = createApp(APP)
// 加载插件
app.use(vue3PluginDemo)
app.mount("#app");
import button from "./button.vue"
import directive from "./directive"
const install = (app: any, options: any) => {
// 方法
app.config.globalProperties.sayHello = function () {
alert('Hello, Nancy!');
}
// 指令
app.directive("my-directive", directive)
// 组件
app.component('my-button', button)
}
export default install
<template>
<span :style="{ 'color': props.fontColor, 'font-size': props.fontSize + 'px' }" class="bt">
<slot></slot>
</span>
</template>
<script setup>
const props = defineProps({
fontColor: { type: String, default: '' },
fontSize: { type: Number, default: 14 }
})
</script>
<style scoped>
.bt {
border: 1px solid black;
border-radius: 3px;
padding: 5px 10px;
}
</style>
第一个 el 当前绑定的DOM 元素
第二个 binding
第三个 当前元素的虚拟DOM 也就是Vnode
第四个 prevNode 上一个虚拟节点,仅在 beforeUpdate 和 updated 钩子中可用
const focusRange = {
// 当挂载时
mounted(el: any, binding: any, vnode: any, prevNode: any) {
// color
el.___newColor = binding.value + ""
el.___oldColor = el.style.borderColor
el.onclick = () => {
if (el.style.borderColor == el.___oldColor) {
el.style.borderColor = el.___newColor
} else {
el.style.borderColor = el.___oldColor
}
}
},
// 当值更新时
update(el: any, binding: any, vnode: any, prevNode: any) {
el.___newColor = binding.value + ""
el.style.borderColor = el.___newColor
},
unmounted(el: any, binding: any, vnode: any, prevNode: any) {
},
}
export default focusRange
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。