首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何运行vue指令函数?

如何运行vue指令函数?
EN

Stack Overflow用户
提问于 2021-04-01 11:03:15
回答 1查看 35关注 0票数 0

我有这个vue 2 cli指令

代码语言:javascript
复制
directives: {
swipe: {
  inserted: function runme(el) {
  alert(el);
    },
  },
},

如何从方法或其他指令运行runme(obj)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-01 14:40:09

您可以将通用代码分解到它自己的独立方法中,该方法可以从任何地方调用:

代码语言:javascript
复制
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)
    }
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66897886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档