javascript - 如何在vue组件外部的外部js modul文件中调用vue组件方法
问题描述
我不知道如何在外部 js 模块中调用 Vue 设置组件方法 getStageLine。
我的 vue 组件 isis 的代码示例:
const settings = {
template: '#templateName',
created:function(){
this.getStageLine();
},
data:function(){
return{
test1:[],
test:[],
}
},
mounted(){
},
methods:{
getStageLine:function(){
axios.get(databaseConf.url + '/' + blaa)
.then(response => {
this.test1 = response.data
})
.catch(e => {
this.errors.push(e)
})
axios.get(databaseConf.url + '/' + lol)
.then(response => {
this.test = response.data
})
.catch(e => {
this.errors.push(e)
})
}
我的外部 js 模块的代码示例:
var dash = (function(){
function addSomething(data){
console.log(data);
$.ajax({
url:'',
type: 'POST',
data: data ,
success: function (response) {
console.log(response.status);
location.reload();
},
error: function () {
alert("error");
}
});
}
});
我想在 dash.addSomething(data) 函数内调用 Vue 组件之外的 getStageLine 方法。
我试过 $refs 调用然后 Vue.component.componentName.methods.methodName 但这没有用,所以任何建议如何在 Vue 之外调用该函数,我尝试了堆栈中的其他示例,但它们对我不起作用。
解决方案
推荐阅读
- linux - 如何在 Linux 中更改权限模式?
- c++ - 递归函数总是返回 False
- javascript - 使用 Hooks 和标签更新 React 状态
- ios - 如何将视图控制器设置为 rootviewcontroller
- python - 对四列执行haversine函数到新列
- javascript - 尝试删除 ComponentDidMount 甚至 Render 中的引导类时,React 应用程序出错
- python - 如何修复文件处理输出问题,我得到两次打印相同的输出
- javascript - 如何将可关闭的文本标签添加到 Textarea Kendo | jQuery
- javascript - 在 react-native 中获取主要颜色?
- tensorflow - 当我将列表对象添加到 keras 子类模型时,`tf.model_to_estimator` 引发 AttributeError