vue3.0 写法 格式

utils/utils.js

import { reactive, toRefs } from 'vue'

import { useStore } from 'vuex'

export default function () {

  const store = useStore()

  const dictionary = reactive({

    dictionaryMap: {},

    dictionaryList: []

  })

  const getDictionary = async (code) => {

    const response = await store.dispatch('dictionary/getDictionary', code)

    dictionary.dictionaryList = response

    const result = {}

    response.forEach(item => {

      result[item.value] = item.label

    })

    dictionary.dictionaryMap = result

    return { list: response, map: result }

  }

  return {

    ...toRefs(dictionary),

    getDictionary

  }

}

引入

import useDictionary from '@/mixins/dictionary'

    const { dictionaryMap, dictionaryList, getDictionary } = useDictionary()

使用

    onBeforeMount(() => {

      getDictionary('login')

      getCaptcha()

      notifyHandle()

    })

相关推荐

  1. vue3.0 写法 格式

    2023-12-06 23:38:07       27 阅读
  2. vue基本写法

    2023-12-06 23:38:07       15 阅读
  3. vue中样式动态绑定写法

    2023-12-06 23:38:07       30 阅读
  4. Vue2和Vue3自定义指令的写法

    2023-12-06 23:38:07       34 阅读
  5. vue3:中warch监听的几种写法

    2023-12-06 23:38:07       36 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-06 23:38:07       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-06 23:38:07       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-06 23:38:07       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-06 23:38:07       20 阅读

热门阅读

  1. TCP与UDP的区别

    2023-12-06 23:38:07       44 阅读
  2. 基于Boost::Beast模块的小型HTTP服务器编程

    2023-12-06 23:38:07       34 阅读
  3. Spark_spark参数配置优先级

    2023-12-06 23:38:07       39 阅读
  4. spark写入数据报错

    2023-12-06 23:38:07       36 阅读
  5. pymysql的基本用法

    2023-12-06 23:38:07       41 阅读
  6. 网络数据通信—ProtoBuf实现序列化和反序列化

    2023-12-06 23:38:07       38 阅读
  7. git小白初学习

    2023-12-06 23:38:07       29 阅读
  8. 让 OpenAI GPT4 出 10 道题测试其他开源大语言模型

    2023-12-06 23:38:07       23 阅读
  9. 什么是DDI?DDI的原理和作用是什么?一文看懂

    2023-12-06 23:38:07       35 阅读
  10. USTC Fall2023 高级人工智能期末考试回忆版

    2023-12-06 23:38:07       39 阅读
  11. 力扣labuladong一刷day29天二叉树

    2023-12-06 23:38:07       39 阅读
  12. 还记得当初自己为什么选择计算机?

    2023-12-06 23:38:07       32 阅读
  13. Spring第四课,MVC终章,应用分层的好处,总结

    2023-12-06 23:38:07       32 阅读