javascript - VueJS - 如何从指令访问 mixin 方法
问题描述
简单代码:
Vue.mixin(
{
methods :
{
test ()
{
return 'test';
}
},
}
);
Vue.directive('my-directive',
{
inserted (el)
{
this.test();
}
}
);
[Vue 警告]:指令 my-directive 插入钩子中的错误:“TypeError:无法读取未定义的属性 'test'”
解决方案
Vue.mixin(
{
methods :
{
test ()
{
return 'test';
}
},
}
);
Vue.directive('my-directive',
{
inserted (el)
{
//
},
bind(el, binding, vnode)
{
vnode.context.test();
}
}
);
推荐阅读
- wordpress - 从 url 获取产品,每 15 分钟更新一次?
- c - C 中的调试错误:进程停止,错误代码为 139
- apache - Apache 反向代理和 ShinyProxy
- python - 如何突出显示搜索查询结果中的单词
- ruby-on-rails - 从 JS 库到 Rails 的 CSRF
- sql - 为什么添加另一个 WHERE 子句会更改我的 sql 语句变量的类型?
- reactjs - 如何将道具从组件发送到 Redux FieldArray
- java - Java中如何正确实现生产者-消费者
- angular - Angular中的传单没有正确调整大小
- azure - Azure YAML 管道:动态查找组中的变量