wumi_blog
wumi_blog copied to clipboard
v-ref 子组件索引 从外部js调用挂在子组件上的方法
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);
}