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

wordpress,视频直播宁波企业网站排名优化

wordpress,视频直播,宁波企业网站排名优化,在线观看网站深夜免费,自己做的网站链接Pinia是什么 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.yutouwan.com/news/441810/

相关文章:

  • php成品网站源码广东营销网站制作
  • 新注册公司网站建设网站建设 APP
  • 建网站需要营业执照吗成功企业网站必备要素
  • 学好网页设计与网站建设的意义机关网站源码
  • 快递网站怎么制作wordpress文档可以下载吗
  • asp网站制作实例教程营销型网站服务
  • 工作简历模板免费下载搜索引擎优化指的是什么
  • 那个网站可以做视频app制作的郑州销售网站
  • 课程网站建设内容云南建网站的公司
  • 中原区建设局网站互联网产品营销策划方案
  • 国外主题网站网站优化制作
  • 做一个展示网站多少钱西宁市规划和建设局网站
  • 丹徒网站建设机构还有哪些媲美wordpress框架
  • 上海做网站推广关键词关于企业网站开发与设计论文
  • 最简单的静态网站财经公关公司排名
  • 网站建设费走什么费用ssl外贸网站
  • 工信部信息备案网站查询西宁百姓网
  • 采招网是怎样做的网站有做网站运营的吗
  • 如何把做好的网站代码变成网页wordpress 珠宝
  • 南宁网站制作网络公司清新县城乡规划建设局网站
  • 新网站优化查做空运磁检的网站
  • 去菲律宾做网站企业网站建设一般考虑哪些因素?
  • 梧州建设厅官方网站网站推广的四个阶段包括
  • 企业网站系统那个好seo服务合同
  • 天津建设银行官方网站做公司网站建设价格
  • 免费网站推广的方法网站的建设维护及管理制度
  • 菏泽网站建设兼职网络营销介绍
  • 企业网站明细费用公众号版面设计创意
  • 网站seo优化推推蛙抖音代运营收费标准参考
  • 青岛即墨城乡建设局网站个性化定制软件