一、添加数据要绑定的数据
data () {
return {
words: [
{
content: "耳朵终将遇到耳朵",
date: "2020-05-05 9:49",
author: "耳朵"
},
{
content: "耳朵终将遇到耳朵",
date: "2020-05-05 9:49",
author: "耳朵"
}
]
}
二、在需要绑定循环的标签里加入 v-for
v-for="item in words" :key="item.id"
三、获取数据
<li v-for="item in words" :key="item.id" class="list-item">
<el-card class="card-body" shadow="hover">
<p class="card-word">{{item.content}}</p>
<p><span class="card-date">{{item.date}}</span>
<span class="card-author">by:{{item.author}}</span></p>
</el-card>
</li>
四、通过服务器加载数据
1.添加钩子函数(已挂载函数)
mounted: function () { //钩子函数(已挂载)
this.loadWords()
},
2.调用加载函数
methods: {
loadWords(){
var _this = this
this.$axios.get('/words').then(resp =>{
if(resp && resp.status === 200){
_this.words = resp.data
}
})
},