vue+ajax的實現


html

<tr>
<td>用戶名</td>
<td id="t01"><input type="text" name="user_name" v-model="user_name" v-on:blur="check">{{ message }}</td>
</tr>

如果想要在ajax中獲取當前文本框的值,得在文本框內加入一個屬性  v-model="你的屬性名"

然后在這里用了一個失焦事件

js

<script>
var vue=new Vue({
  el: '#t01',
  data: {
    message: '',
    user_name:"" //在下方使用的必須先聲明
  },
methods:{
  check:function(){
    var zhi=this.user_name;
    //console.log(zhi);
    $.ajax({
      url:"yoururl",
      data:{zhi:zhi},
      dataType:"json",
      type:"POST",
      success:function(res){
        console.log(res);
        vue.message=res.msg;
     }
    })
   }
  },
})
</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM