如何编写 Vue 插件
在以往的 Vue 项目开发过程中,我们使用插件的方法是Vue.use(plugin)。如:
import filters from "....编写 Vue 长按指令
根据官方文档:
// 注册一个全局自定义指令 `v-focus`
Vue.directive('focus', {
// 只调用一次,指令第一次绑定到元素时调用。...在这里可以进行一次性的初始化
bind: function (el, binding, vnode, oldVnode) {
},
// 当被绑定的元素插入到 DOM 中时……
inserted...: function (el) {
// 聚焦元素
el.focus()
},
// 所在组件的 VNode 更新时调用,但是可能发生在其子 VNode 更新之前。...但是你可以通过比较更新前后的值来忽略不必要的模板更新
update: function (el, binding, vnode, oldVnode) {
},
// 指令所在组件的 VNode