数据请求:store请求

这种是写在actions里面的

写这种请求要注意

写请求是一个步骤,写引入是一个步骤,写使用又是一个步骤 接下来请看:

一、写请求
import { updateState } from "@/utils/appFunc";
import { Request } from "@/utils/xhr";

export default {
  namespaced: true,
  state: {
  },
  mutations: {
    updateBillHallState: updateState,
  },
  actions: {
    async addCounterfoil ({ state }, params) {
      return await Request.fetch({ url: '/api/counterfoil/addCounterfoil', method: 'POST', ...params });
    },
    async countRemainingDays ({ state }, params) {
      return await Request.fetch({
        url: '/api/counterfoil/countRemainingDays', method: 'GET', ...params
      });
    },
}
 modules: {
  }
}
二、写引入
 ···········································这个是用传值的方式,但是注意,请求 和 方法名    (不可同名)
  <fixed-price-modal
      :get-list="getList"
      v-model="fixedPriceModal.visible"
      :get-platforms="getPlatforms"
      :get-contracts="getContracts"
      :get-detail-show-ids="getDetailShowIds"
    ></fixed-price-modal>

 ···········································在你需要使用的地方引入
methods: {
    ...mapActions('billHall', [
      'getBillList',
      'getPlatform',
      'getContract',
      'getDetailShowId',
    ]),
    async getList(params) {
      return await this.getBillList(params)
    },
    async getPlatforms(params) {
      // console.log(params)
      return await this.getPlatform(params)
    },
    async getContracts(params) {
      return await this.getContract(params)
    },
    async getDetailShowIds(params) {
      return await this.getDetailShowId(params)
    },
  },
三、写使用
 props: {
    getPlatforms: {
      // 获取表格数据action方法
      type: Function,
      default: () => new Promise((resolve) => resolve({ data: [] })),
    },
}
methods:{
  platformChange() {
      // console.log('平台合同')
      this.getPlatforms({
        params: {},
      }).then((res) => {
        if (res.code == 0) {
          // console.log(res)
          this.contractList = res.data
        }
      })
    },
}
························································也可以写在created()里
created() {
    this.getPlatforms({
      params: {},
    }).then((res) => {
      if (res.code == 0) {
        // console.log(res)
        this.contractList = res.data
      }
    }),
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • PS:转载请注明出处作者: TigerChain地址: https://www.jianshu.com/p/218...
    TigerChain阅读 26,332评论 5 70
  • vue的核心是什么? Vue 的核心设计理念可以概括为以下 5 个关键要素,这些要素共同构成了 Vue 的独特优势...
    Aniugel阅读 9,733评论 3 21
  • 数据请求知多少 老铁们都知道上网是通过浏览器发送HTTP请求,接着服务器后收到请求,发送资源到浏览器,然后浏览器解...
    山野乔治阅读 1,139评论 1 0
  • AFHTTPRequestOperationManager 网络传输协议UDP、TCP、Http、Socket、X...
    Carden阅读 4,432评论 0 12
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 7,579评论 16 22