A
A
Andrey2017-09-14 19:03:00
Vue.js
Andrey, 2017-09-14 19:03:00

Is it possible to access the action in vuex not through assembly?

I implement vue into the finished site, for example, such a state
file is taken from the change

import Vue from 'vue'

const namespaced = true;

const state = todos;

const getters = {
  search: state => state.search
}

const actions = {
  clearSearch({commit}){
    commit('CLEAR_SEARCH');
  },
}


const mutations = {
  CLEAR_SEARCH(state) {
    state.search = []
  }
}

export default {
  namespaced,
  state,
  getters,
  actions,
  mutations
}

assembly via vue-cli
is it possible to call an action by a script on the site,
UPD: there are many ways to do this https://stackoverflow.com/questions/37656592/defin...
example
import store from './store';
...
window.store = store;

UPD 1:
More correct option
in main.js
import Vue from 'vue'
import store from './store'
import FavoriteItem from './components/FavoriteItem'
...
let components = {
  FavoriteItem
}
export {
  Vue,
  store,
  components,
};

in webpack config
output: {
    path: config.watch.assetsRoot,
    filename: utils.assetsPath('js/[name].js'),
    library: "build"
  },

and in normal js you can call build, there will be new build.Vue, build.components.FavoriteItem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Shashenkov, 2017-09-14
@teknik2008

Make a public method and call. This is js - no matter how you do it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question