当前位置: 首页 > news >正文

福州鼓楼区建设局网站推介做resume的网站

福州鼓楼区建设局网站,推介做resume的网站,做网站什么软件,wordpress邮箱配置stmpPinia是什么 Pinia是Vue的最新状态管理工具#xff0c;是Vuex的替代品 比Vuex更大的优势在于#xff1a; 1.提供更加简单的API#xff08;去掉了mutation#xff09; 2.提供符合#xff0c;组合式风格的API#xff08;和Vue3新语法统一#xff09; 3.去掉了modules…Pinia是什么 Pinia是Vue的最新状态管理工具是Vuex的替代品 比Vuex更大的优势在于 1.提供更加简单的API去掉了mutation 2.提供符合组合式风格的API和Vue3新语法统一 3.去掉了modules的概念每一个store都是一个独立的模块 4.配合TypeScript更加友好提供可靠的类型推断 手动添加Pinia到Vue项目 在实际开发项目的时候关于Pinia的配置可以在项目创建时自动添加 现在初次学习从零开始 1.使用Vite创建一个空的Vue3项目 npm create vuelatest 2.按照官方文档安装pinia到项目中 官方文档Pinia | Pinia 先装包 在mian.js文件中添加以下语句 import { createPinia } from pinia const pinia createPinia() app.use(pinia) 基本语法 在src文件夹下创建一个名为store的文件夹创建js文件 定义数据 JS文件中编写语句定义数据export导出仓库仓库里的变量要return出去才能去使用 仓库变量名use仓库名Store import { defineStore } from pinia import { ref } from vue//定义store //defineStore(仓库的唯一标识,(){...}) export const useCounterStore defineStore(counter, () {//声明数据stateconst count ref(0)//声明操作数据的方法 action(普通函数)//声明基于数据派生的计算属性 getters(computed)return {count} }) 使用数据在App.vue和子组件中都是如此 script setup import { useCounterStore } from /store/counter.js const counterStore useCounterStore() console.log(counterStore.count) /scripttemplate{{ counterStore.count }} /template 定义操作数据的方法 JS文件中编写语句定义方法仓库里的方法要return出去才能去使用 import { defineStore } from pinia import { ref } from vue//定义store //defineStore(仓库的唯一标识,(){...}) export const useCounterStore defineStore(counter, () {//声明数据stateconst count ref(0)//声明操作数据的方法 action(普通函数)const addCount () count.valueconst subCount () count.value--//声明基于数据派生的计算属性 gettersreturn {count,addCount,subCount} }) 使用方法 script setup import { useCounterStore } from /store/counter.js const counterStore useCounterStore() /scripttemplatediv{{ counterStore.count }}brbutton clickcounterStore.addCount/buttonbutton clickcounterStore.subCount-/button/div /template 定义计算属性用computed实现getter import { defineStore } from pinia import { computed, ref } from vue//定义store //defineStore(仓库的唯一标识,(){...}) export const useCounterStore defineStore(counter, () {//声明数据stateconst count ref(0)//声明操作数据的方法 action(普通函数)const addCount () count.valueconst subCount () count.value--//声明基于数据派生的计算属性 gettersconst double computed(() count.value * 2)return {count,addCount,subCount,double} }) 使用计算属性 script setup import { useCounterStore } from /store/counter.js const counterStore useCounterStore() /scripttemplatediv{{ counterStore.double }}/div /template action异步实现 Pinia中不需要mutationaction既支持同步也支持异步 编写方式异步action函数的写法和组件中获取异步数据的写法完全一致 安装axios yarn add axios 在store文件夹下创建一个新的JS文件channel.js import { defineStore } from pinia import { ref } from vue import axios from axiosexport const useChannelStore defineStore(channel, () {//声明数据const channelList ref([])//声明getters相关const getList async () {const { data: { data } } await axios.get(http://geek.itheima.net/v1_0/channels)channelList.value data.channels}return {channelList,getList} }) 数据获取和渲染 script setup import { useChannelStore } from /store/channel.js const channelStore useChannelStore() /scripttemplatebutton clickchannelStore.getList获取频道数据/buttonulli v-foritem in channelStore.channelList :keyitem.id{{ item.name }}/li/ul /template storeToRefs方法 如果对仓库直接解构使用不进行处理数据会丢失响应式 比如 script setup import { useCounterStore } from /store/counter.js const counterStore useCounterStore() const {count}counterStore /scripttemplate{{ count }} /template 如果想保持数据响应式可以在解构的时候使用storeToRefs方法不过解构函数不需要使用storeToRefs方法直接解构就可以 script setup import { storeToRefs } from pinia import { useCounterStore } from /store/counter.js const counterStore useCounterStore() const { count } storeToRefs(counterStore) /script Pinia调试 持久化 持久化插件官方文档快速开始 | pinia-plugin-persistedstate 1.安装包 npm i pinia-plugin-persistedstate 2.在main.js中编写 import { createPinia } from pinia //导入pinia持久化的插件 import piniaPluginPersistedstate from pinia-plugin-persistedstateconst pinia createPinia() const app createApp(App) app.use(pinia.use(piniaPluginPersistedstate)) 3.使用根据自己编写的语法选择添加 persist: true 如果这个模块添加了持久化那么用户修改的数据会被存储到本地刷新也是修改后的加载时也是优先从本地读取数据 修改一些默认配置可以参考配置 | pinia-plugin-persistedstate persist: {key: my-channels,//修改本地存储的唯一标识storage: sessionStorage,//存储到什么中paths: [channelList]//存储的是哪些数据}
http://www.ihoyoo.com/news/5698.html

相关文章:

  • 全响应式网站用什么做的wordpress countdown timer
  • 网站开发都用什么浏览器模板网站很牛
  • flash做导航网站知春路网站建设公司
  • 网站跳转至手机端如何做wordpress 扩展
  • 电子商务网站推广策划方案江苏镇江论坛
  • 动漫网站开发需求分析沧州句号网络科技有限公司
  • 网站开发负责人是什么职位燕郊做网站找谁
  • 产品展示网站建设公司营销策划方案
  • 网站建设流图visio创建个人网站教案
  • 互联网网站建设营销试用平台网站建设
  • 建筑公司网站新年贺词wordpress的前端怎么写
  • 网站建设案例行情专做程序员招聘的网站
  • 中国建设银行浙江省丽水市分行网站网页网站设计制作
  • 网站首页欣赏中山建设工程招聘信息网站
  • 网站建设开发价格高吗做专门的表白网站
  • 北京市保障性住建设投资中心网站首页网络公司建设网站
  • 个人搭建网站教程烟台网站制作维护
  • 视频网站公共关系怎么做网站导航栏效果
  • 建设网站模板下载自己做婚恋网站
  • 大良营销网站建设效果网站开发的技术
  • 邢台建网站找谁百度服务电话6988
  • 学做ps的软件的网站游戏公司官方网站建设方案
  • 360建筑网如何修改名字站长工具seo排名
  • 做电脑网站起什么名字网站开发工程师职位概要
  • 360如何做网站优化一些简单的代码
  • 深圳商业网站建设推荐公司长沙网站建设公司哪家好
  • 合肥专业做网站手机制作网页软件
  • 电子商务网站开发视频响应式网站如何实现
  • wordpress安装教程 l深圳快速seo排名优化
  • 钦州市建设局网站商标免费设计在线生成