vue數據內容爲接口請求
export default {
name: "weather",
created() {
axios.get("/laravel/test").then(response => {
var res = response.data;
console.log(res);
this.info_msg = res;
});
},
data() {
return {
info_msg: null,
};
}
這裏這個created讓你先把數據拿過來 然後初始化data的info_msg 可以完成頁面;列表的初始化。
誤區:
methods: {
eat() {
console.log("you eat");
return "this is methods eat";
},
test() {
console.log("you test");
return "zxl";
},
getNewsList() {
// axios.get("/laravel/test").then(response => {
// var res = response.data;
// console.log(res);
// this.$options.data.info_msg = res;
// });
//return i++;
this.info_msg = i++;
}
},
data() {
return {
info_msg:this.getNuewsList(),
};
}
};
在method聲明請求方法,data中直接請求this.方法。 不成!!!
頁面渲染不等你把數據抓捉來,直接渲染頁面結束了 。把這個取數據放到created()搞定!!!