testmess.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //第一步
  2. import Vue from 'vue';
  3. import Vuex from 'vuex';
  4. import _ from 'lodash';
  5. Vue.use(Vuex);
  6. const api = {
  7. //接口地址
  8. company: `/api/servicetest/testmess`,
  9. };
  10. const state = () => ({});
  11. const mutations = {};
  12. const actions = {
  13. //查询列表 skip:第一页,limit:第一页显示的数据,info:其余查询参数
  14. async query({ commit }, { skip = 0, limit, ...info } = {}) {
  15. //连接接口。。。。
  16. const res = await this.$axios.$get(`${api.company}`, {
  17. skip,
  18. limit,
  19. ...info,
  20. });
  21. //把数据集合res返回
  22. return res;
  23. },
  24. //创建数据 payload是添加form表单中的数据集合 创建数据的时候需要拿到form表单里面的数据
  25. async create({ commit }, payload) {
  26. //通过$axios提交post请求????
  27. const res = await this.$axios.$post(`${api.company}`, payload);
  28. return res;
  29. },
  30. //查询详情,payload:参数位,一般传当前数据id
  31. async fetch({ commit }, payload) {
  32. //有/一般都是路径
  33. const res = await this.$axios.$get(`${api.company}/${payload}`);
  34. return res;
  35. },
  36. //修改:id: 当前数据id, data: 当前修改数据的新form表单
  37. async update({ commit }, { id, ...data }) {
  38. const res = await this.$axios.$post(`${api.company}/update/${id}`, data);
  39. return res;
  40. },
  41. //删除:payload:参数位,一般传当前数据id
  42. async delete({ commit }, payload) {
  43. const res = await this.$axios.$delete(`${api.company}/${payload}`);
  44. return res;
  45. },
  46. };
  47. export default {
  48. namespaced: true,
  49. state,
  50. mutations,
  51. actions,
  52. };