Below is the code snippet from my store.js file:
import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios/dist/axios';
import VueAxios from 'vue-axios'
const api = axios.create({
baseURL: 'mybase.com',
timeout: 2000,
});
Vue.use(VueAxios, api)
Vue.use(Vuex);
export default new Vuex.Store({
strict: process.env.NODE_ENV !== 'production',
state: {
name: null,
YOB: null,
gender: null,
city: null,
daily_goal: null,
balance: null,
today_video_count: 17,
video_credit: 5,
},
mutations: {
updateDailyGoal(state, value) {
state.daily_goal = value;
},
addVideoCredit(state) {
state.balance += state.video_credit;
},
reduceDonation(state, amount) {
state.balance -= amount;
},
setVideoCount(state, count) {
state.today_video_count = count;
},
initialize(state, profile) {
state.name = profile.name;
state.YOB = profile.YOB;
state.gender = profile.gender;
state.city = profile.city;
state.daily_goal = profile.daily_goal;
state.balance = profile.balance;
},
},
actions: {
submitVideoView({commit}, payload) {
// this.$http.post('/vid');
commit('addVideoCredit');
},
setDailyGoal({commit}, value) {
// this.$http.post('/account/daily-goal', {daily_goal: value});
commit('updateDailyGoal', value);
},
init({commit}) {
// this.$http.get('/account/profile').then(response => {
// commit('initialize', response);
// });
// this.$http.get('/account/vid-view').then(response => {
// commit('setVideoCount', response);
// });
},
},
created() {
dispatch('init');
},
});
I encountered an error stating that undefined doesn't have a post property, indicating that this.$http is not defined. How can I address this issue? Additionally, here is the relevant portion of my main.js file:
import Vue from "nativescript-vue";
import App from "./components/App";
import store from "./store";
new Vue({
store,
render: (h) => h("frame", [h(App)]),
}).$start();
I would greatly appreciate any feedback or suggestions on how to enhance this code. I have searched extensively for documentation on setting this up correctly but haven't found anything useful. Please note that I only want the init action to be dispatched once at the start of each user session or app launch.