我还有另一个人的一些额外代码。而且我不知道该怎么用
我尝试使用此功能,就像index.js中存储的任何其他组件一样 在index.js中,我注册了模块:
export const store = new Vuex.Store({
state: {},
getters: {},
mutations: {},
actions: {
},
modules: {
person,
applications,
},
strict: false
});
let fillTotal = function (s) {
return{...}};
export default function (fatJSON) {
let obj = fillTotal(fatJSON);
obj = Object.assign(demoObj, obj);
axios.post(
'http://someaddress',
obj
).then(r => console.log(r));
// console.log('obj', obj);
// console.log('fatStore', fatStore);
}
我的组件
template>
<div>
<div class="clear_save_button row">
<button @click="onSave">Сохранить</button>
</div>
</div>
</template>
<script>
import myFunction from '/src/store/index.js'
methods: {
executeMyFunction(FatJson){
myFunction(FatJson);
},
onSave() {
this.executeMyFunction(this.person);
AXIOS.post(`/profile`, (this.person))
.then(response => {...
我在组件中具有post方法,例如:AXIOS.post(/profile
,(this.person))
如何发送this.person使用商店中的此功能?
答案 0 :(得分:0)
只需导入该函数并在这样的方法中调用它即可:
已更新:
// src/store/index.js
let fillTotal = function(s) {...}
export const myFunction = (fatJSON) => {
let obj = fillTotal(fatJSON);
obj = Object.assign(demoObj, obj);
axios.post(
'http://1ss.loc',
obj
).then(r => console.log(r));
}
// in component.vue
import {myFunction} from '@/src/store/index.js';
export default {
methods: {
executeMyFunction() {
myFunction();
}
}
}