update函数里面获取不到吗?
写一个demo给你看看(可以直接全部复制粘贴):
Document
new Vue({
el: "#app",
data() {
return {
value: ""
};
},
methods: {},
directives: {
view: {
bind: function(el) {
el.style.visibility = "hidden";
},
update: function(el, binding) {
if (binding.value) {
el.style.visibility = "visible";
el.style.cssText = "width:50px;height:50px;background:#f00;";
} else {
el.style.visibility = "hidden";
el.style.cssText = "";
}
},
unbind: function() {}
}
}
});