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

网站建设销售问答seo排名培训

网站建设销售问答,seo排名培训,建设银行网站修改手机号,电子商务运营推广1.vuex的使用 一、uniapp中有自带vuex插件,直接引用即可 二、在项目中新建文件夹store,在main.js中导入 在根目录下新建文件夹store,在此目录下新建index.js文件 index.js import Vue from vueimport Vuex from vuexVue.use(Vuex)const store new Vuex.Store(…

1.vuex的使用

一、uniapp中有自带vuex插件,直接引用即可

二、在项目中新建文件夹store,在main.js中导入

在根目录下新建文件夹store,在此目录下新建index.js文件
在这里插入图片描述
index.js

import Vue from 'vue'import Vuex from 'vuex'Vue.use(Vuex)const store = new Vuex.Store({state: {//公共的变量,这里的变量不能随便修改,只能通过触发mutations的方法才能改变},mutations: {//相当于同步的操作},actions: {//相当于异步的操作,不能直接改变state的值,只能通过触发mutations的方法才能改变}
})
export default store

在main.js中导入挂载vuex

import Vue from 'vue'
import App from './App'
import store from './pages/store/index.js'
Vue.prototype.$store = storeVue.config.productionTip = falseApp.mpType = 'app'const app = new Vue({store,...App
})
app.$mount()

2.使用

第一种方式:this. s t o r e 直接操作例如当取值:直接在页面中使用 t h i s . store直接操作 例如当取值:直接在页面中使用this. store直接操作例如当取值:直接在页面中使用this.store.state.变量名

第二种方法:mapState, mapGetters, mapActions, mapMutations

<template><view class="content"></view>
</template><script>import { mapState, mapGetters, mapActions, mapMutations } from 'vuex'//导入export default {data() {return {}},computed: { //computed中注册...mapGetters(['text1']),...mapState(['text1'])}methods: {...mapMutations([]),...mapActions([])}}
</script><style>
</style>

3.vuex持久化

问题:

H5应用中存在Vuex中的数据在刷新页面后丢失了。

原因:

Vuex的 store 中的数据是保存在运行内存中的,当页面刷新时,页面会重新加载 Vue 实例,Vuex数据会重新初始化,导致页面刷新Vuex中的数据丢失的问题。

解决:

使用 vuex-persistedstate 插件
1、在项目目录下执行:npm install --save vuex-persistedstate;
2、修改store/index.js

import Vue from 'vue'
import Vuex from 'vuex'
import persistedState from "vuex-persistedstate"Vue.use(Vuex)const store = new Vuex.Store({plugins: [persistedState({storage: {getItem: key => uni.getStorageSync(key),setItem: (key, value) => uni.setStorageSync(key, value),removeItem: key => uni.removeStorageSync(key)}})],state:{//存放状态"username":'',"userid":''},mutations:{//...},actions:{//...},//...
})export default store

使用后浏览器打开用控制台调试可看数据存放在 window.localStorage.vuex
这里其实就和调用uniapp提供的数据缓存API存放的数据位置一样了,官方文档链接:https://uniapp.dcloud.io/api/storage/storage.html

注意:在APP-PLUS环境下,这个数据在应用退出时默认不会被清空(或者说初始化)。
原文链接:https://blog.csdn.net/Mr_Bobcp/article/details/125876232

http://www.hkea.cn/news/894814/

相关文章:

  • 安卓手机怎么做网站站长工具seo综合查询广告
  • 余姚网站建设的公司手机百度账号申请注册
  • 预付网站制作费怎么做凭证如何自制网站
  • 定制网站多少钱北京seo网站管理
  • 南昌做网站公司哪家好如何建立独立网站
  • 成都解放号网站建设什么是百度竞价
  • 网站优化的基本思想与原则百度号码
  • 沧州网站建设制作设计优化深圳seo优化推广
  • 建立一个网站需要什么技术网上培训机构
  • 网站设计与管理论文百度账号注册平台
  • 网站空间商推荐seo是什么职位缩写
  • 怎么建设boss网站文件外链
  • 百度推广网站建设费百度搜索引擎的网址是多少
  • php 手机网站 上传图片定制网站建设
  • 关于网站建设的问题百度关键词分析
  • 登录官方网站装修公司网络推广方案
  • 设计网站官网入口网站搜索优化方法
  • 网站优化qq群山东做网站
  • wordpress icomoon太原seo快速排名
  • 中华建设杂志网站记者数据指数
  • 网站开发测试情况南召seo快速排名价格
  • 上海仓储公司小红书seo优化
  • 南京建设公司网站网络营销整合推广
  • wordpress更改语言沈阳seo优化
  • wordpress免费网站世界大学排名
  • 做网站的属于什么专业?百度爱采购竞价推广
  • 网站建设一年多少恰东莞网站到首页排名
  • 新企业网站应该怎么做SEO优化广告联盟有哪些
  • 手机app开发网站建设软文推广文章案例
  • 网站自然排名百度经验官网登录