#變量和字符串的拼接#
寫項目中,遇到了這樣的一個問題:怎樣在一個div里面顯示兩個data中的數據?我的問題描述清楚了嗎。。。
看圖吧:
這是用戶最初的需求~
這是用戶后來的需求,嗯……就是多了個文件的總數量~
最初代碼:
data() { return{ banner[ {id: 0,name: "全部文件"}, {id: 0,name: "招生簡介"}, {id: 0,name: "其他文件"} ] } }
后期代碼:
data() {
return{
banner[
{id: 0,name: ""},
{id: 0,name: ""},
{id: 0,name: ""}
],
//這里我只是隨意寫了個數值,具體值,當然是從后台傳過來的呀~
allFilesCount:1000,
recrIntroCount:200,
otherFilesCount:7000
}
},
methods:{
//變量和字符串拼接的方法
adds:function() {
//``這個符號需要注意,英文狀態下,Esc下面那個鍵。
this.banner[0].name = `全部文件(${this.allFilesCount})`;
this.banner[1].name = `招生簡介(${this.recrIntroCount})`;
this.banner[2].name = `其他文件(${this.otherFilesCount})`;
}
},
mounted() {
this.adds();//最后,調用一下上面那個賦值的方法
}
