样式:
<select v-model="score">
<option v-for="s in scoreList" :key="s" :value="s">
{{ s }} 星
</option>
</select>
代码
mounted() {
this.loadComments()
},
渲染页面完成后,调用函数。
导入axios使用http链接
import axios from 'axios'
使用例子如下:
axios.get('http://localhost:8080/comment/list', {
params: {
productId: this.productId
}
}).then(res => {
this.commentList = res.data.data
})
就是链接请求:
举例:
http://localhost:8080/comment/list? productId=1001;
axios的post
axios.post('/comment/add', {
productId: this.productId,
userId: this.userId,
content: this.content,
score: this.score
}).then(() => {
alert('评论成功')
this.content = ''
this.score = 5
this.loadComments()
})
其中的productId,userId,content,score以json传给后端,
后端以
RequestBody接收。