vue 数据更新的一个问题

0 0 javascript vue.js
90后攻城狮
90后攻城狮

声望值:78 0人

2019-02-12 14:35:39 提问

关注 0关注

收藏 0收藏, 72浏览

初学VUE,发现要个问题,让我无法理解
html:



请输入要查询的省份:

{{answer}}

因为别的我用的不孰,所以我直接引了个JQ进行AJAX通信
js:

     var watchExampleVM=new Vue({
      el:"#watch-example",
      data:{
        question:'',
        answer:'省份ID查询'
      },
      watch:{
        //如果 question  发生改变,这个函数会执行
        question:function(newQuestion){
          this.answer='正在查询..';
          this.getAnswer();
        }
      },
      methods:{

        getAnswer:function(){

          var tAnswer=this.answer;
          console.log(tAnswer);  //  在这里我拿了一下数据,数据是正常的
          var pName=this.question;
          if(this.question!=""){
            $.ajax({
              type:'post',
              url:'http://192.168.1.1:8383/_API/_province/get',
              data:null,
              success:function(data){
                if(data.code=='E0000'){
                  for(var i=0;i

为什么明明是全等的引用传递,在jq的AJAX里是更新不了的,可是直接写确是可以更新?

这是我的响应数据:

{"code":"E0000","data":[{"id":"1","name":"北京市","icon":"beijing","fid":"0","definition":"1","level":"1"},{"id":"22","name":"天津市","icon":"T","fid":"0","definition":"1","level":"1"},{"id":"43","name":"河北省","icon":null,"fid":"0","definition":"1","level":"6"},{"id":"227","name":"山西省","icon":null,"fid":"0","definition":"1","level":"6"},{"id":"472","name":"辽宁省","icon":null,"fid":"0","definition":"1","level":"6"},{"id":"587","name":"吉林省","icon":null,"fid":"0","definition":"1","level":"6"},{"id":"657","name":"黑龙江省","icon":null,"fid":"0","definition":"1","level":"6"},{"id":"801","name":"上海市","icon":"S","fid":"0","definition":"1","level":"1"},{"id":"823","name":"江苏省","icon":null,"fid":"0","definition":"1","level":"6"},{"id":"943","name":"浙江省","icon":null,"fid":"0","definition":"1","level":"6"},{"id":"1045","name":"安徽省","icon":null,"fid":"0","definition":"1","level":"6"},{"id":"1168","name":"福建省","icon":null,"fid":"0","definition":"1","level":"6"},{"id":"1263","name":"江西省","icon":null,"fid":"0","definition":"1","level":"6"},{"id":"1374","name":"山东省","icon":null,"fid":"0","definition":"1","level":"6"}]}
请先 登录 后评论

0个回答

注册新账号

悬赏追问
10
  • 10
  • 20
  • 50
  • 100
  • 200
  • 输入数值
发布追问