wumi_blog icon indicating copy to clipboard operation
wumi_blog copied to clipboard

v-ref 子组件索引 从外部js调用挂在子组件上的方法

Open 5Mi opened this issue 8 years ago • 0 comments

这里提到过v-ref子组件索引

EMC项目中遇到一种情况,安卓提供的接口回调的函数要在页面index.js中挂载在window上,这时就有这么个需求:从外部js中调用挂载在vue组件上的action方法

...
vuex:{
  actions:{
     //这里的方法会被挂载到相应实例上
  }
}
//index.js中

//vue实例
let vueAddcard = new Vue({
    el:'#emc-app',
    components:{
        addcard
    },
    store
})

//扫二维码返回s
window.showTxtResult = function(s) {
    //通过子组件索引找到子组件addcard
    vueAddcard.$refs.addcard.updateCardByTdcode(s);
}

5Mi avatar Jun 28 '16 07:06 5Mi