uni-app传参,发送请求和vuex
同步 uni.setStorageSync('cunData', this.curID); uni.getStorageSync('cunData') uni.removeStorageSync('cunData') 异步 uni.setStorage({ key: 'Token', data: res.data.row_data.record.User_ID + '^' + res.data.row_data.record.Token }) uni.setStorage({ key: 'UserInfo', data: JSON.stringify(res.data.row_data.record) }) getSession(){ let UserInfo = uni.getStorageSync('UserInfo') let info = {} if (UserInfo) { info = JSON.parse(UserInfo) this.$nextTick(() => { this.info.yhm = info.User_ID this.info.name = info.User_Name }) } },
<template> <view>{{msg}}</view> </template> <script> export default{ data(){ return{ msg:'', } }, onLoad(option) { console.log(option) this.msg = option.msg }, } </script>
/page/xx?msg=123123123
uni.request
传一个值 data:{ '':this.curId }, header:{ 'Content-Type': 'application/x-www-form-urlencoded', 'token':this.$utils.getToken(), }, 传JSON data: JSON.stringify(obj), header:{ 'token':this.$utils.getToken(), }, 什么都不传 method:'POST', header:{ 'Content-Type': 'application/x-www-form-urlencoded', },
main.js
// vuex import store from './store/index.js'
Vue.prototype.$store = store
const app = new Vue({
store,//挂载
...App
})
app.$mount()
store文件夹index.js
import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const store = new Vuex.Store({ state: { pWidth:2000, pHeight:2000 }, mutations: { setpWidth(state, val) { console.log(val) state.pWidth = Number(val) }, setpHeight(state, val) { console.log(val) state.pHeight = Number(val) }, }, actions: { } }) export default store
.vue页面
<template> <view class="list" <!-- vuex用 --> <view class="biaodan"> <uni-forms ref="setForm" :modelValue="formData" label-position="top"> <uni-forms-item label="宽度"> <uni-easyinput type="number" v-model="formData.width" placeholder="请输入" /> </uni-forms-item> <uni-forms-item label="高度"> <uni-easyinput type="number" v-model="formData.height" placeholder="请输入" /> </uni-forms-item> </uni-forms> <button type="primary" @click="submit">提交</button> </view> </view> </template> <script> import {mapMutations} from 'vuex';//vuex用 export default { name:'list', data() { return {//vuex用 formData:{ width:'', height:'' } } }, components: { }, created() { //vuex用 this.formData.width = this.$store.state.pWidth this.formData.height = this.$store.state.pHeight }, onLoad() { }, onShow(...options){ }, methods: { //vuex用 ...mapMutations(['setpWidth','setpHeight']), submit(){ this.setpWidth(this.formData.width) this.setpHeight(this.formData.height) }, } } </script> <style lang="scss" scoped> .list{ .biaodan{ margin: 30rpx; } } </style>
const app = new Vue({store,//挂载 ...App})app.$mount()