laravel - Laravel 7 Vue 获得收藏按钮
问题描述
这部分有什么问题吗?在控制台上得到这个
app.js:38308 [Vue 警告]:未知的自定义元素:-您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。
(在发现 )
这是代码
<template>
<span>
<a href="#" v-if="isFavorited" @click.prevent="unFavorite(post)">
<i class="fa fa-heart"></i>
</a>
<a href="#" v-else @click.prevent="favorite(post)">
<i class="fa fa-heart-o"></i>
</a>
</span>
</template>
<script>
export default {
props: ['post', 'favorited'],
data: function() {
return {
isFavorited: '',
}
},
mounted() {
this.isFavorited = this.isFavorite ? true : false;
},
computed: {
isFavorite() {
return this.favorited;
},
},
methods: {
favorite(post) {
axios.post('/favorite/'+post)
.then(response => this.isFavorited = true)
.catch(response => console.log(response.data));
},
unFavorite(post) {
axios.post('/unfavorite/'+post)
.then(response => this.isFavorited = false)
.catch(response => console.log(response.data));
}
}
}
</script>
解决方案
推荐阅读
- html - 我正在尝试更改我网站上的背景颜色
- javascript - 动态创建的元素没有在 React 中触发点击事件
- reactjs - 并非所有日期数据都显示在 x 轴折线图上
- azure-devops - 如何在 azure Release 管道而不是 Build 管道中创建失败的工作项
- verilog - SV ERROR:通过端口连接驱动,被多重驱动
- spring-boot - SpringBoot App,在 Intellij 中运行良好,但调试失败
- r - 从r中的.wav文件名中提取日期和时间
- python-3.x - 如何解决 Python 中读取过多输入的问题
- javascript - 如何推入数组并使用 Id 作为对象的索引
- c# - Listview 页面上的无限滚动