【发布时间】:2018-08-15 23:59:32
【问题描述】:
我的 vue 脚本出现此错误,这是我正在使用的文件 找不到 axios.ad (favoriteAd.vue) 报告的错误。 它基本上是一个最喜欢的功能,使用: https://scotch.io/tutorials/implement-a-favoriting-feature-using-laravel-and-vue-js#comments-section (用广告代替帖子)
app.js
require('./bootstrap');
window.Vue = require('vue');
Vue.component('favorite', require('./components/FavoriteAd.vue'));
const app = new Vue({
el: '#favorite'
});
favoriteAd.vue
<template>
<span>
<a href="#" v-if="isFavorited" @click.prevent="unFavorite(ad)">
<i class="fa fa-heart"></i>
</a>
<a href="#" v-else @click.prevent="favorite(ad)">
<i class="fa fa-heart-o"></i>
</a>
</span>
</template>
<script>
export default {
props: ['ad', 'favorited'],
data: function() {
return {
isFavorited: '',
}
},
mounted() {
this.isFavorited = this.isFavorite ? true : false;
},
computed: {
isFavorite() {
return this.favorited;
},
},
methods: {
favorite(ad) {
console.log(ad);
axios.ad('/favorite/'+ad) // this is the error line
.then(response => this.isFavorited = true)
.catch(response => console.log(response.data));
},
unFavorite(ad) {
axios.ad('/unfavorite/'+ad)
.then(response => this.isFavorited = false)
.catch(response => console.log(response.data));
}
}
}
查看
@if (Auth::check())
<favorite
:ad={{ $aviso->id }}
:favorited={{ $aviso->favorited() ? 'true' : 'false' }}
></favorite>
@endif
【问题讨论】:
-
axios 没有名为
ad的方法。你期待axios.ad(...)做什么? -
favorite() 和 unFavorite() 都接受 ad 道具作为参数。使用 Axios,我向路由(laravel 控制器路由)发出 POST 请求
-
你不应该打电话给
axios.post吗?如果您正在尝试发帖请求? -
没错!发布您的答案,以便我投票!谢谢
-
我将投票结束这个问题,因为这似乎只是一个印刷错误,不太可能对未来的读者有所帮助