javascript - 如何结合jQuery访问Vuejs功能
问题描述
我正在使用一个小项目Laravel
,Vuejs
一切都很好,我喜欢这两个框架。当我尝试goToStep
使用jQuery
$.each
.
顺便说一句jQuery
,已经包括在内并且工作正常。唯一的问题是我无法进入goToStep
里面$.each
。
错误信息 :
Uncaught (in promise) TypeError: this.goToStep is not a function
我的 VuejS 代码:
store: function () {
axios.post("/apartment/", $("form#add-apartment").serialize()).then((response) => {
this.buildings = response.data.buildings;
alert(response.message)
}).catch(error => {
//console.log(error.response.data.errors)
$.each(error.response.data.errors, function(key, value){
var x = $("[name='"+ key +"']").closest("#parent").data('step');
this.goToStep(x)
});
});
},
goToStep: function (value) {
if (!this.validate()) {
return;
}
this.current_step = value;
},
解决方案
代替
$.each(error.response.data.errors, function(key, value){
var x = $("[name='"+ key +"']").closest("#parent").data('step');
this.goToStep(x)
});
...和:
$.each(error.response.data.errors, key => this.goToStep(
$(`[name='${key}']`).closest('#parent').data('step')
));
我做了什么:
推荐阅读
- excel - 为什么更改参考单元格时公式不适用于相同的数据
- angular - 如何测试现代角度应用程序的性能/负载
- javascript - 如何在浏览器上实时在我的html中添加脚本代码打开它
- java - Actuator /metrics 端点不包括 http.server.requests
- sql - 结合 IFNULL、SUM 和 WHERE 函数来显示可用金额
- java - 在 Vaadin (Java) 的传单插件映射中向 LayersControl 添加监听器
- jquery - Jquery 表单插件不会在 Bootstrap 模式中提交
- javascript - 如何获取用户的当前位置?
- python - 如何设置与未使用的分类间隔索引相对应的熊猫数据框列中的值?
- excel - 用于检查列的 VBA 代码只有公式