简体   繁体   English

vue.js 我如何使用 axios.get 我的代码不起作用

[英]vue.js how can i use axios .get my code is doesnt working

i want use axios.get and get some data in my database but it have a error.我想使用 axios.get 并在我的数据库中获取一些数据,但它有一个错误。

this is my store.js code这是我的 store.js 代码

 export default new Vuex.Store({ state: { test: null }, mutations: { testt(state, payload) { state.test = payload; } }, actions: { testFun({ commit }) { axios.get("http://localhost:8070/beer").then(response => { let test = { id: response.data.data.id, title: response.data.data.title, subtitle: response.data.data.subtitle }; commit("testt", test); }); } } });

this is my app.vue code这是我的 app.vue 代码

 <script> import { mapState, mapActions } from "vuex"; export default { props: { source: String }, data: () => ({ drawer: null }), computed: {...mapState(["isLogin"]) }, methods: {...mapActions(["testFun"]) } }; </script>
 <v-list-item router:to="{name: 'test'}" exact @click="testFun()"> <v-list-item-action> <v-icon>mdi-contact-mail</v-icon> </v-list-item-action> <v-list-item-content> <v-list-item-title>test</v-list-item-title> </v-list-item-content> </v-list-item>

this.is my testt.vue code这是我的 testt.vue 代码

 <script> import { mapState } from "vuex"; export default { computed: {...mapState(["test"]) }, data() { return { beer: [] }; }, mounted() { // } }; </script>
 <template> <div> <h1>Beer List</h1> <div v-for="beer in test":key="beer.id">{{ beer.title }}</div> </div> </template>

and i have router and my database is no problem because i texting path in my controller path it was working but it doesn't woring on vue我有路由器,我的数据库没有问题,因为我在我的 controller 路径中发短信路径它正在工作,但它在 vue 上没有工作

but result is error this is errormessage TypeError: Cannot read property 'title' of null但结果是错误,这是错误消息 TypeError: Cannot read property 'title' of null

Brother in your back-end request the title variable are not exist in your json response kindly check and let me know.兄弟在您的后端请求中,您的 json 响应中不存在标题变量,请检查并告诉我。 if you still facing any issue.如果您仍然面临任何问题。

Thanks谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM