Laravel,Vue:对象(…;)不是函数
我刚接触Laravel,尝试处理一些api调用。我正在制作一个带有管理面板的仪表板来处理用户。现在我想向端点添加一些数据,但每次我想从另一个视图导入函数时,它都会说:对象(…)不是函数。我找了thorugh stackoverflow,找到了这篇文章,但它并没有解决我的问题 TypeError:对象(…)不是函数 在resetStoreState(0.js:3252) 在新店(0.js:2993) 位于Module../resources/js/store.js(1.js:498) 在网页上需要(app.js:64) 位于Module../resources/js/services/http_service.js(1.js:462) 在网页上需要(app.js:64) 模块../resources/js/services/category_service.js(1.js:443) 在网页上需要(app.js:64) 在Module../node_modules/babel loader/lib/index.js/node_modules/vue loader/lib/index.js/resources/js/views/Categories.vue?vue&type=script&lang=js&(1.js:14) 在网页上需要(app.js:64) 我的代码:Laravel,Vue:对象(…;)不是函数,laravel,vue.js,Laravel,Vue.js,我刚接触Laravel,尝试处理一些api调用。我正在制作一个带有管理面板的仪表板来处理用户。现在我想向端点添加一些数据,但每次我想从另一个视图导入函数时,它都会说:对象(…)不是函数。我找了thorugh stackoverflow,找到了这篇文章,但它并没有解决我的问题 TypeError:对象(…)不是函数 在resetStoreState(0.js:3252) 在新店(0.js:2993) 位于Module../resources/js/store.js(1.js:498) 在网页上需要
<script>
//without the import here it works. as soon as I import it, it crashes
import * as createCategory from '../services/category_service';
...
methods: {
createCategory: async function() {
let formData = new FormData();
formData.append("name", this.categoryData.name);
formData.append("image", this.categoryData.image);
try {
//const response = await categoryService.createCategory(formData);
//console.log(response);
} catch (error) {
alert("error");
}
}
...
http\u服务
import {http, httpFile} from './http_service';
export function createCategory(data) {
return httpFile().post('/categories', data);
}
import store from '../store';
import axios from 'axios';
export function http() {
return axios.create({
baseURL: store.state.apiURL
});
}
export function httpFile() {
return axios.create({
baseURL: store.state.apiURL,
headers: {
'Content-Type' : 'multipart/form-data'
}
});
}
以及存储以供参考
import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
apiURL: 'http://localhost:8000/api',
serverPath: 'http://localhost:8000'
},
mutations: {},
actions: {}
});
老实说,我不知道这里出了什么问题
更新: app.js
import Vue from 'vue';
import App from './App.vue';
import router from './router';
import {store} from './store';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap';
import BootstrapVue from 'bootstrap-vue';
Vue.use(BootstrapVue);
new Vue({
el: '#app',
router,
store,
render: h => h(App)
});
解决此问题,这是导出默认值的问题 in-store.js
从“Vue”导入Vue;
从“Vuex”导入Vuex;
Vue.use(Vuex);
导出常量存储=新建Vuex.store({
声明:{
apiURL:'http://localhost:8000/api',
服务器路径:'http://localhost:8000'
},
突变:{},
动作:{}
});
这里export const store
我添加了
然后在app.js中
从“/store”导入{store};
从“/App.vue”导入应用程序;
新Vue({
el:“应用程序”,
路由器,
商店//在这里使用
});
您需要更改所有导出语法
从“../store”导入存储;
从“axios”导入axios;
export const http=function(){
返回axios.create({
baseURL:store.state.apiURL
});
}
export const httpFile=函数(){
返回axios.create({
baseURL:store.state.apiURL,
标题:{
“内容类型”:“多部分/表单数据”
}
});
}
及
从“/http_服务”导入{http,httpFile};
export const createCategory=函数(数据){
返回httpFile().post('/categories',data);
}
ref link我仍然有相同的错误。现在,即使没有重要性,它也不会加载应用程序,我确实运行了itadd your
app.js
Done。如果有帮助的话,我正在运行Laravel 8。我在你建议的任何地方都更改了它。我还是犯了同样的错误。。。