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

专门做试卷的网站吉林省建设安全信息网

专门做试卷的网站,吉林省建设安全信息网,wordpress 打赏不能用,txt网站推荐前言 毕竟尤大佬都推荐使用pinia#xff0c;支持vue2和vue3#xff01; 如果熟悉vuex#xff0c;花个把小时把pinia看一下#xff0c;就不想用vuex了 支持选项式api和组合式api写法pinia没有mutations#xff0c;只有#xff1a;state、getters、actionspinia分模块不…                                               前言 毕竟尤大佬都推荐使用pinia支持vue2和vue3 如果熟悉vuex花个把小时把pinia看一下就不想用vuex了 支持选项式api和组合式api写法pinia没有mutations只有state、getters、actionspinia分模块不需要modulespinia 没有命名空间模块。pinia 无需动态添加底层通过 getCurrentInstance 获取当前 vue 实例进行关联。pinia 是平面结构利于解构没有嵌套可以任意交叉组合。 先介绍两个官网 pinia官网 保持pinia的数据持久化用pinia-plugin-persistedstate 推荐使用这个其他的也可以如pinia-plugin-persist可能会遇到bug pinia-plugin-persistedstate 官网 如果需要对本地存储加密的话使用 secure-ls 插件原理是重构localStorage 和 sessionStorage 的setItem和getItem方法同理vuex里面也可以使用 secure-ls 网址 安装 npm install pinia pinia-plugin-persistedstate创建store 在根目录下创建store文件夹新建index.ts文件 import { createPinia } from pinia; import createPersistedState from pinia-plugin-persistedstate; //引入pinia数据持久化插件 const pinia createPinia(); pinia.use(createPersistedState); export default pinia; 挂载 Pinia数据持久化及数据加密 这里使用的pinia数据的持久化和本地加密存储 pinia中不在用modules分模块简单理解一个ts文件一个模块吧注意每个模块尽量统一风格导出变量use开头 下面是个示例 store文件夹中的 counter.ts 这里用到了数据持久化和数据加密 import { defineStore } from pinia; // 定义一个pinia的一个模块 //这里是练习pinia用的 import type { StorageLike } from pinia-plugin-persistedstate; import SecureLS from secure-ls; // encryptionSecret:自定义密钥 const ls new SecureLS({isCompression: false,encryptionSecret: 38c31684-d00d-30dc-82e0-fad9eec46d1d, }); const st: StorageLike {setItem(key: string, value: string) {ls.set(key, value);},getItem(key: string): string | null {return ls.get(key);}, };//第一个参数是id标识pinia的名字第二个参数是个对象 export const useCounterStore defineStore(counter, {state: () {return {count: 10,msg: 菠萝头的使用,price: 100,};},actions: {add() {this.count 1;},del() {this.count - 1;},promiseIncrement() {return new Promise((resolve) {setTimeout(() {this.count;resolve(this.count);}, 1000);});},priceAdd(a: any, b: any) {console.log(a, b);this.price;},},getters: {getCount(state) {//在使用时把方法名当属性用就行return state.count * state.price;},},// persist: true, 默认存储在 localStorage上面的persist: {storage: st, // 上面申明的类型// storage: localStorage,// key: counter,}, }); moduleIdentifiers.ts文件无加密 import { defineStore } from pinia;let moduleIdentifiers: ArrayString [];export const useModuleIdentifiers defineStore(moduleIdentifiers, {state: () {return {moduleIdentifiers,};},actions: {setModuleIdentifiers(aside: ArrayString) {this.moduleIdentifiers aside;},},getters: {},persist: true,// persist: {// storage: localStorage,// }, }); 页面中使用 templatea-layout classlayoutHeader /a-layout-content classmain-containera-button clickback返回上一页/a-buttondiv classtitleh1pinia/h1div classbutton-boxa-button typeprimary clicktest去练习vuex/a-buttona-button typeprimary clickchangePina(1)add同步/a-buttona-button typeprimary clickchangePina(2)promise异步/a-buttona-button typeprimary clickchangePina(3)test/a-buttona-button typeprimary clickchangePina(5)$patch/a-buttona-button typeprimary clickchangePina(6)getters/a-buttona-button typeprimary clickchangePina(4)reset/a-button/div/divdiv classcarda-buttonstata.count: {{ count }}/a-buttona-buttonstata.msg: {{ msg }}/a-buttona-buttonstata.price: {{ price }}/a-button/div/a-layout-content/a-layout /templatescript langts setup import { reactive, computed } from vue; import { useRouter } from vue-router;import Header from //components/Header/index.vue;import { useCounterStore } from //store/counter;import { storeToRefs } from pinia; let pinia useCounterStore();//使用storeToRefs解构保持响应性当然也可以直接结构根据具体情况而定 let { count, price, msg, getCount } storeToRefs(pinia); // const count computed(() pinia.count) const changePina (type: number) {if (type 1) {pinia.add();} else if (type 2) {pinia.promiseIncrement();} else if (type 3) {pinia.priceAdd(1, 2);} else if (type 4) {pinia.$reset();} else if (type 5) {pinia.$patch((state) {state.count 2;state.price 2;state.msg $patch批量修改;});} else if (type 6) {console.log(pinia.getCount);//如果想使用解构一定要用 storeRoRefsconsole.log(getCount);} }; const router useRouter();const test () {router.push(/ncov/test); }; const back () {router.push(/ncov/task); }; /scriptstyle langless scoped .layout {min-width: 1400px;min-height: 100vh; }.main-container {flex-direction: row;min-height: calc(100vh - 76px);padding: 19px 70px;background-color: bg-color; }.title {font-weight: 600;font-size: 24px;margin: 30px 0;.flex-type(space-between);:deep(.ant-btn) {margin-left: 10px;} }.card {background-color: white-color;padding: 30px;:deep(.ant-btn) {margin-left: 10px;} }.select-box {margin-bottom: 40px;.flex-type(flex-start);:deep(.ant-select) {width: 120px;margin-right: 40px;} }:deep(.ant-cascader-menu-item:hover) {background: bg-color; }:deep(.ant-input:focus, .ant-input:hover, .ant-cascader-input:hover) {border-color: rgba(122, 132, 198, 1); } /style 详情解析 上面的代码已经包含了 State、Getters、Actions同步/异步、$reset、$patch、 State存数据 Getters计算属性 Actions更改state的值 $reset重置state到最初状态 $patch批量修改state的值 其他还有替换所有state的值等参考官网
http://www.hkea.cn/news/14458609/

相关文章:

  • 服装微信商城网站建设怎样下载网页上的视频
  • 山东省建设厅执业资格注册中心网站扬中新闻头条新闻
  • 企业网站功能模块编程入门自学软件
  • 个人网站备注模板通用网站后台管理 asp.net 源码
  • 天津市住房和城乡建设厅官方网站企业网站建设组织人员可行性分析
  • 江苏住房和建设厅网站新强生产建设兵团网站
  • 哈尔滨网站优化对策h5美食制作网站模板下载
  • 网站建设丶金手指花总11漳州建设项目公告网站
  • 服装网站的建设策划正规现货交易平台app
  • 做网站页面大小多大如何做一个网站推广自己的产品
  • 邢台移动网站建设价格株洲网站开发
  • 法学网站阵地建设2024近期新闻
  • 做徒步网站怎么样网站建设合同需要交印花税吗
  • 站内推广的方式有哪些夏天做那些网站致富
  • 成功的电商网站jsp网站开发简单代码
  • 建设新农村网站广告创意网站
  • 网站 优化 件建设一个好的网站
  • 关键词是网站seo的核心工作实战营销型网站建设
  • 学校多语言网站建设有了域名怎样做网站
  • 南京网站创建杭州网站排名服务
  • 如何判断网站程序使用asp还是php宜昌市网站建设
  • 建立网站的成本湖北大网站建设
  • ps网站导航条素材网站集群建设实施方案
  • 怎么成立个人网站韩国平面设计网站
  • 网站上papi酱做的音频电脑网页视频下载
  • 网站推广项目p2p理财网站开发流程
  • 罗湖住房和建设局网站织梦文章类网站模板
  • 建好了网站怎么做外贸东莞住房城乡建设部官网
  • 临淄网站建设公司河南智慧团建登录入口官网
  • 学校网站建设风险分析erp系统教学