我是前端小白萌新一枚 最近在用uniapp写一个app 遇到不少坑 特此记录一下啦~~
一开始我存储数据时用vue中的store 在登陆的时候把获取到的个人信息存储在store的仓库里面,
然后在每个页面需要的地方获取数据 例如获取用户id
1.store /index.js
import Vue from "vue"; import Vuex from "vuex"; Vue.use(Vuex); const store = new Vuex.Store({ state: { userInfo: {} }, mutations: { getUser(state, info) { state.userInfo = info
//写入缓存 uni.setStorage({ key: 'userInfo', data: info }) console.log(state.userInfo) }, clearInfo(state){ state.userInfo = {} } } }); export default store;
2.调用
<script> export default { data() { return { vidList: {} } }, onLoad() { this.getVideos() }, methods: { getVideos() { let userid = uni.getStorageSync('userInfo').uid; console.log(userid); var that = this;
uni.request({ url: "/api/study/stulog?uid="+userid, success(res) { that.vidList = res.data.data } }) }, } } </script>
直接写入缓存
标签:app,state,userInfo,刷新,uni,data,store From: https://www.cnblogs.com/79524795-Tian/p/17034150.html