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

中国建设银行北京分行门户网站公告淘宝代运营一般多少钱

中国建设银行北京分行门户网站公告,淘宝代运营一般多少钱,做视频网站需要多大带宽,购买手机网站推荐Vue 项目中的状态优化一般都会用Pinia替代Vuex#xff0c;Pinia 是 Vue 生态系统中的一个轻量级状态管理库#xff0c;作为 Vuex 的替代品#xff0c;它提供了更简洁的 API 和更好的性能。模块化管理#xff1a;使用 Pinia 时#xff0c;建议将状态拆分为多个 store 模块Pinia 是 Vue 生态系统中的一个轻量级状态管理库作为 Vuex 的替代品它提供了更简洁的 API 和更好的性能。模块化管理使用 Pinia 时建议将状态拆分为多个 store 模块以避免单一状态树过于庞大和复杂。这不仅有助于维护还能提升性能。懒加载 Store通过 Pinia 的 defineStore 动态创建 store当某个 store 仅在特定页面或组件中需要时可以延迟加载它。这样可以减少应用的初始加载时间。State 持久化如果某些状态需要在页面刷新后保持可以使用 Pinia 的插件功能将状态持久化到 localStorage 或 sessionStorage避免不必要的网络请求或重新计算。避免不必要的深度响应Pinia 允许你明确哪些状态需要响应式哪些不需要。对于不需要响应式的复杂对象可以使用 shallowRef 或 shallowReactive 来减少响应式开销。1. 安装 Pinia 与配置 npm install pinia设置 Pinia import { createApp } from vue import { createPinia } from pinia import App from ./App.vueconst app createApp(App)// 创建 Pinia 实例 const pinia createPinia()app.use(pinia) app.mount(#app) 2. 创建模块化 Store创建两个 Store 模块userStore 和 productStore。其中 userStore 将使用状态持久化productStore 将演示懒加载和避免不必要的深度响应。stores/userStore.js // stores/userStore.js import { defineStore } from pinia import { ref, computed, watch } from vueexport const useUserStore defineStore(user, () {// 初始化状态如果 localStorage 中有存储优先使用存储的状态const name ref(localStorage.getItem(user-name) || John Doe)const age ref(parseInt(localStorage.getItem(user-age)) || 25)const doubleAge computed(() age.value * 2)// 监听状态变化并将其保存到 LocalStoragewatch(() name.value,(newValue) {localStorage.setItem(user-name, newValue)})watch(() age.value,(newValue) {localStorage.setItem(user-age, newValue.toString())})return {name,age,doubleAge,} })stores/productStore.js // stores/productStore.js import { defineStore } from pinia import { shallowRef } from vueexport const useProductStore defineStore(product, () {// 使用 shallowRef 来避免不必要的深度响应const products shallowRef([])const addProduct (product) {products.value.push(product)}return {products,addProduct,} })3. 懒加载 StoreproductStore 仅在需要时加载例如在某个特定组件中。components/ProductList.vue templatedivh2Product List/h2ulli v-forproduct in products :keyproduct.id{{ product.name }}/li/ulbutton clickaddNewProductAdd Product/button/div /templatescript setup import { useProductStore } from stores/productStore import { onMounted } from vue// 懒加载 productStore const productStore useProductStore() const products productStore.productsconst addNewProduct () {productStore.addProduct({ id: Date.now(), name: Product ${products.length 1} }) }onMounted(() {console.log(ProductList component mounted.) }) /script4. 在其他组件中使用 userStorecomponents/UserProfile.vue templatedivh2User Profile/h2pName: {{ name }}/ppAge: {{ age }}/ppDouble Age: {{ doubleAge }}/p/div /templatescript setup import { useUserStore } from /store/userStore// 使用 userStore这个 Store 状态会被持久化 const userStore useUserStore()const { name, age, doubleAge } userStore /script5. 手动实现状态持久化我们在 userStore 中通过 localStorage 手动实现了状态持久化。如果你需要更加通用的状态持久化插件可以创建一个简单的 Pinia 插件。plugins/persistedState.js // plugins/persistedState.js export function createPersistedStatePlugin(options {}) {return ({ store }) {const { key store.$id } options// 从 LocalStorage 初始化状态const fromStorage localStorage.getItem(key)if (fromStorage) {store.$patch(JSON.parse(fromStorage))}// 订阅状态变化并将其保存到 LocalStoragestore.$subscribe((mutation, state) {localStorage.setItem(key, JSON.stringify(state))})} }注册插件 import { createPinia } from pinia import { createPersistedStatePlugin } from ./plugins/persistedStateconst pinia createPinia() pinia.use(createPersistedStatePlugin())const app createApp(App) app.use(pinia) app.mount(#app)
http://www.zqtcl.cn/news/592542/

相关文章:

  • 做seo网站优化哪家强济南网站建设公司排名
  • tp5网站文档归档怎么做手机虚拟机哪个好用
  • 网站建设公司的业务范围万网做网站多少钱
  • 做网站要用写接口6wordpress 汽车租赁
  • 网站开发方向paypal账号注册
  • 如何选择做pc端网站重庆平台网站建设企业
  • 一个人做网站好累电子商城采购流程
  • 网站制作维护价格信息网站建设方案
  • 如何选择建网站公司能看人与动物做的网站
  • 温州网站建设方案外包不能访问子目录的网站
  • 建设拼多多一样网站需要多少钱wordpress企业站主题免费
  • 无锡网站制作哪家公司好做微信文章的网站
  • 网站 制作信产部网站备案
  • 做流程图表的网站网络营销推广网站收录
  • iis5.1怎么新建网站电子商务网站建设与管理实训内容答案
  • 做网站背景步骤知名的vi设计公司
  • 中国室内设计师联盟网站我注册过的网站
  • 如何给自己的公司做网站网站设计电商首页
  • 成都网站开发培训综合网站开发实训总结
  • 个人备案网站名称文学网站开发
  • 花钱做推广广告哪个网站好泗洪网页设计
  • 望牛墩镇网站建设公司网站建设企业熊掌号
  • 做网站一般会出现的问题静态网站的好处就是安全性好从而
  • 做海鲜代理在什么网站建筑网片钢筋网生产厂家
  • 万网网站建设方案书导购网站开发要多少钱
  • 做网站muse好还是DW好用wordpress %link
  • html5门户网站模版做投标需要知道什么网站
  • 合肥网站制作推广seo引擎搜索网站关键词
  • 陕西建设厅网站wordpress 不显示ip
  • 郑州外贸网站制作营销号视频生成器手机版