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>

猜你喜欢

转载自www.cnblogs.com/sdfgdrg/p/10689351.html
今日推荐