zoukankan      html  css  js  c++  java
  • vue使用,问题

    参考链接:https://cn.vuejs.org/v2/guide/index.html

    *)[Vue warn]: Error in v-on handler: "TypeError: $form.postJSON is not a function"

    [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

    *)必须把js代码写进body里的script里,是因为代码没有自动执行(未解决,一引入jquery(或者uikit的js)就不行了)

        <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名,像下面这个自动提示时证明成功了

  • 相关阅读:
    LeetCode-Path Sum I & II & III
    LeetCode-Unique Binary Search Trees I & II
    LeetCode-230. Kth Smallest Element in a BST
    LeetCode-98. Validate Binary Search Tree
    LeetCode-450. Delete Node in a BST
    LeetCode-108. Convert Sorted Array to Binary Search Tree
    LeetCode-129. Sum Root to Leaf Numbers
    视频中人体轮廓检测
    新型SVM
    Surveillance Monitering入门学习论文笔记
  • 原文地址:https://www.cnblogs.com/Gaoqiking/p/10781042.html
Copyright © 2011-2022 走看看