vue.js - 如何运行 vue 指令功能?
问题描述
我有这个 vue 2 cli 指令
directives: {
swipe: {
inserted: function runme(el) {
alert(el);
},
},
},
如何从方法或其他指令运行 runme(obj)
解决方案
您可以将通用代码分解为可以从任何地方调用的独立方法:
function swipeInserted(el, binding, vnode) {
alert(el)
}
export default {
directives: {
swipe: {
inserted: swipeInserted,
},
other: {
inserted(el, binding, vnode) {
swipeInserted(el, binding, vnode)
// other code specific to this directive...
}
}
},
methods: {
runInserted() {
const el = {/*...*/}
const binding = {/*...*/}
const vnode = {/*...*/}
swipeInserted(el, binding, vnode)
}
}
}
推荐阅读
- css - 如何自定义水平滚动条
- azure-devops - Azure 数据工厂的 Azure DevOps CI-CD 管道
- javascript - 用 Javascript 从 Parquet 编写 CSV 的更好方法
- typescript - Apollo withFilter 不通知客户端
- python - 如何从 Databricks 中的 Python 笔记本创建日志记录到 ADLS Gen2(无需安装)?
- c# - Xamarin相对布局约束类RelativeToParent意外输出?
- python - Python & Sqlite:在 sqlite 表中,我有一个 id、name 和 point。我有一个 id 列表,我想按点对它们进行排序
- flutter - Flutter intl 生成文件,null 安全问题
- html - 通过 unix 邮件发送 HTML 文档类型并添加附件
- solr - TYPO3 10 SOLR 语言和 baseVariants 站点 config.yaml