标签:tde for js代码 vuejs 一个 错误 invoke blog play
参考链接:https://cn.vuejs.org/v2/guide/index.html
[Vue warn]: Error in v-on handler: "TypeError: $form.postJSON is not a function" (found in <Root>) warn @ vue.js:634 logError @ vue.js:1893 globalHandleError @ vue.js:1888 handleError @ vue.js:1848 invokeWithErrorHandling @ vue.js:1871 invoker @ vue.js:2188 original._wrapper @ vue.js:7541 #错误2 vue.js:1897 TypeError: $form.postJSON is not a function at Vue.submit (forTest.html:94) at invokeWithErrorHandling (vue.js:1863) at HTMLFormElement.invoker (vue.js:2188) at HTMLFormElement.original._wrapper (vue.js:7541)
报错代码
var vms = new Vue({ el: ‘#vm‘, data: { email: ‘‘, passwd: ‘‘ }, methods: { submit: function (event) { console.log(1); event.preventDefault();//和form中添加v-on:submit.prevent="submit"是一样的 var $form = $(‘#vm‘), email = this.email.trim().toLowerCase(), data = { email: email, passwd: this.passwd === ‘‘ ? ‘‘ : CryptoJS.SHA1(email + ‘:‘ + this .passwd).toString() }; $form.postJSON(‘/api/authenticate‘, data, function (err, result) { if (!err) { console.log(2); // location.assign(‘/‘); } }); } } });
应该是$form.postJson()中的数据写法除了问题,参考https://blog.csdn.net/qq_36370731/article/details/80290680
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script> $(function () {//必须放在这里 console.log(2); var app2 = new Vue({ el: ‘#app-2‘, data: { message: ‘页面加载于 ‘ + new Date().toLocaleString() } }) })
更新:必须把这个写进body里的script里的标签里,就算只有一个vue也必须这样,否则会未定义vue名,像下面这个自动提示时证明成功了
标签:tde for js代码 vuejs 一个 错误 invoke blog play
原文地址:https://www.cnblogs.com/Gaoqiking/p/10781042.html