<div id="app"> <my-comp v-if="msg" :msg="msg"></my-comp> <button @click="update">更新</button> <button @click="uninstall">卸载</button> <button @click="install">安装</button> </div>
Vue.directive('hello', {
bind: function (el) {
console.log('bind')
},
inserted: function (el) {
console.log('inserted')
},
update: function (el) {
console.log('update')
},
componentUpdated: function (el) {
console.log('componentUpdated')
},
unbind: function (el) {
console.log('unbind')
}
})
var myComp = {
template: '<h1 v-hello>{{msg}}</h1>',
props: {
msg: String
}
}
new Vue({
el: '#app',
data: {
msg: 'Hello'
},
components: {
myComp: myComp
},
methods: {
update: function () {
this.msg = 'Hi'
},
uninstall: function () {
this.msg = ''
},
install: function () {
this.msg = 'Hello'
}
}
})
bind: function (el) {
console.log(el.parentNode) // null
console.log('bind')
},
inserted: function (el) {
console.log(el.parentNode) // <div id="app">...</div>
console.log('inserted')
}
update: function (el) {
console.log(el.innerHTML) // Hello
console.log('update')
},
componentUpdated: function (el) {
console.log(el.innerHTML) // Hi
console.log('componentUpdated')
}
Vue.directive('hello', {
bind: function (el, binding) {
// 在 bind 钩子中初始化库实例
// 如果需要使用父节点,也可以在 inserted 钩子中执行
el.__library__ = new Library(el, binding.value)
},
update: function (el, binding) {
// 模版更新意味着指令的参数可能被改变,这里可以对库实例的参数作更新
// 酌情使用 update 或 componentUpdated 钩子
el.__library__.setOptions(Object.assign(binding.oldValue, binding.value))
},
unbind: function (el) {
// 释放实例
el.__library__.destory()
}
})
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有