我在angular2中制作了这样的数组,并且我还制作了一个表格来填写表格并且效果很好.但我的问题是在没有填写表单的情况下将一些值放在此数组中的最佳方法是什么,我想在此数组中已有一些内容.
employeeList = new Array<{name:string, bio:string, job:string, salery:string, url:string}>();
Run Code Online (Sandbox Code Playgroud) 我已经开始在应用程序中实现Vuex,因此决定将商店拆分为模块。
一开始,我只创建了一个模块来测试Vuex模块的工作方式,因为我以前没有任何经验。
我创建了一个modules文件夹,里面有一个名为Company的模块文件夹。在公司文件夹中,我创建了下一个文件:action.js,getters.js,index.js,mutations.js。
这些文件中的代码:
action.js:
import api from '@/vuex/utils/api'
const getCompanies = (context) => {
api.get('/57/companies').then(response => {
context.commit('GET_COMPANIES', response)
}).catch((error) => {
console.log(error)
})
}
export default {
getCompanies
}
Run Code Online (Sandbox Code Playgroud)
注意:在我导入的api中,我只是创建了用于基本操作的方法(get,post,delete等)。
getters.js:
const allCompanies = state => state.companies
export default {
allCompanies
}
Run Code Online (Sandbox Code Playgroud)
突变.js:
const GET_COMPANIES = (state, companies) => {
state.companies = companies
}
export default {
GET_COMPANIES
}
Run Code Online (Sandbox Code Playgroud)
index.js:
import actions from './action'
import getters from './getters'
import mutations from …Run Code Online (Sandbox Code Playgroud)