Vue:[Vue warn]: Failed to resolve directive: changeColor(found in <Anonymous>)报错解决
代码:// 自定义指令Vue.directive('changeColor', {inserted: function(el, binding) {el.style.color = binding.value}})报错:[Vue warn]: Failed to resolve directive: chan...
·
代码:
// 自定义指令
Vue.directive('changeColor', {
inserted: function(el, binding) {
el.style.color = binding.value
}
})
报错:
[Vue warn]: Failed to resolve directive: changeColor(found in )
原因:
1.自定义指令名存在大写
2.全局的自定义指令需要写在 new Vue() 的前面
正确代码:
// 自定义指令
Vue.directive('changecolor', {
inserted: function(el, binding) {
el.style.color = binding.value
}
})
var vm = new Vue({
el: '#app',
data: {
color: 'red'
}
})
更多推荐
已为社区贡献5条内容
所有评论(0)