在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ VUEJS 收到服務(wù)器的值后給數(shù)組賦值?

VUEJS 收到服務(wù)器的值后給數(shù)組賦值?

服務(wù)器上接收的數(shù)據(jù)為[{ "name":"TOM" , "age":"16" },{ "name":"JACK" , "age":"18" },{ "name":"marry" , "age":"20" }]
我覺得是html中的循環(huán)代碼有問題,請問哪里出錯了?

<ul v-for="item in items">
<li>{{ item.name }}</li>
<li>{{ item.age }}</li>
</ul>
export default {
    data () {
      return {
        header:'',
        items: [
          {
            name:'',
            age:''
          }
        ]
      }
    },
    methods:{
      postdata(){
        var user_id = this.getcookies('user_id');
        this.$http.post('http://example.com/user',{
            userID:user_id
        }).then(function(data){
            this.items=data.body.data
        }
        )
      }
    }
  }
回答
編輯回答
她愚我

<li v-for="v in items">

<p>{{v.name}}</p>
<p>{{v.age}}</p>

</li>

2018年8月5日 03:19
編輯回答
賤人曾

this的作用域問題 .then((res) => {})這樣寫

2017年11月5日 10:00
編輯回答
涼薄

應(yīng)該是this的指向問題,var self = this;

2018年1月27日 19:24
編輯回答
假灑脫

循環(huán)沒問題啊,this.items拿到的是錯的啊。屬于this指向問題,你并沒有成功賦值呢

this.$http.post('http://example.com/user',{
            userID:user_id
        }).then((data)=>{//這里用箭頭函數(shù)
            this.items=data.body.data//this指向Vue實例了
        }
        )
2018年8月24日 11:47