局部自定义指令
例:
<template>
<div v-has >
按时
</div>
</template>
<script>
import store from '../store/index'
export default {
data () {
return {
}
},
created () {
console.log(this.$store);
},
mounted () {
},
directives: {
has: {
// 指令的定义
inserted: function (el,binding) {
console.log(el,binding,store,'el');
if(store.state.count){
el.style.display="none"
}
}
}
},
}
全局自定义指令
例:
import Vue from 'vue'
Vue.directive("has",{
inserted: function (el,binding) {
console.log(el,binding,store,'el');
if(store.state.count){
el.style.display="none"
}
}
})
详细内容,请移步:https://cn.vuejs.org/v2/guide/custom-directive.html