異步請求的值放在vuex中,然后頁面掛載該數據和渲染頁面
computed?計算屬性是基于它的依賴緩存的。計算屬性在它的相關依賴發生改變時會重新取值,所以當ajax請求回來的數據發生變化時,計算屬性的值會進行更新,相關的模板引用也會重新渲染。
//異步請求回來的值
this.$store.state.newslist
<div>{{ fullname }}</div> //隨便綁定會重新生效
computed:{//包含this.$store.state.newslist,會重新執行函數 this.filter
fullname(){
console.log("xxxxxxx",this.filter(this.$store.state.newslist))
return null
},
//函數地方
methods:{
filter(datalist){
const datalist1 = []
datalist.some( (v) =>{//some一旦return true就會跳出循環,。。。。。。。。。。
if(v.aid == 499){
this.$store.state.serviceName = v.title
return true
}
} )
}
}