Laravel 5 未捕获类型错误:axios.ad不是vue脚本中的函数
我的vue脚本出现此错误,这是我正在使用的文件 找不到axios.ad(favoriteAd.vue)报告的错误。 它基本上是一个最受欢迎的功能,使用: (以广告取代邮政) app.jsLaravel 5 未捕获类型错误:axios.ad不是vue脚本中的函数,laravel-5,vue.js,Laravel 5,Vue.js,我的vue脚本出现此错误,这是我正在使用的文件 找不到axios.ad(favoriteAd.vue)报告的错误。 它基本上是一个最受欢迎的功能,使用: (以广告取代邮政) app.js require('./bootstrap'); window.Vue = require('vue'); Vue.component('favorite', require('./components/FavoriteAd.vue')); const app = new Vue({ el: '#fav
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));
}
}
}
导出默认值{
道具:['ad','favorited'],
数据:函数(){
返回{
我喜欢:'',
}
},
安装的(){
this.isFavorited=this.isFavorite?true:false;
},
计算:{
isFavorite(){
把这个还给我;
},
},
方法:{
最爱(广告){
控制台日志(ad);
ad('/favorite/'+ad)//这是错误行
.然后(response=>this.isFavorited=true)
.catch(response=>console.log(response.data));
},
不利因素(ad){
axios.ad('/unfavorite/'+ad)
.然后(response=>this.isFavorited=false)
.catch(response=>console.log(response.data));
}
}
}
查看
@if (Auth::check())
<favorite
:ad={{ $aviso->id }}
:favorited={{ $aviso->favorited() ? 'true' : 'false' }}
></favorite>
@endif
@if(Auth::check())
id}}
:favorited={{$aviso->favorited()?'true':'false'}
>
@恩迪夫
您的应用程序中从未包含axios。尝试npm安装axios
,然后在app.js文件上尝试require('./axios')
。此外,根据axios参考手册,没有名为ad
的方法axios没有名为ad
的方法。您希望axios.ad(…)做什么?favorite()和unFavorite()都接受ad prop作为参数。使用Axios,我向路由(laravel控制器路由)发出POST请求,您是否应该调用Axios.POST
?如果你想发出post请求?没错!张贴你的答案,这样我就可以投票了!谢谢,我将投票结束这个问题,因为这似乎只是一个印刷错误,不太可能对未来的读者有帮助。window.axios=require('axios');window.axios.defaults.headers.common['X-request-With']='XMLHttpRequest';