uniapp对象编辑修改

文章描述:

uniapp如何对一个对象obj值进行修改操作

template

<template>
	<view class="page">
		<view class="flex">
			<view>{{items.name}}</view>
			<view>{{items.age}}</view>
			<view>{{items.like}}</view>
		</view>
		<view @tap="button" class="button">点击</view>
	</view>
</template>

script

var _self;
export default{
	data(){
		return{
			items:{
				name:"小明",
				age:"18",
				like:"读书"
			}
		}
	},
	onLoad() {
		_self = this;
		console.log(_self.items)
	},
	methods:{
		button(){
			_self.$set(_self.items,'age','20')
			console.log(_self.items)
		}
	}
}

style

.page{
	padding: 20upx 15upx;
}
.flex{
	display: flex;
	justify-content: flex-start;
	margin-bottom: 10upx;
}
.flex view{ 
	margin-right: 10upx;
}
.button{ 
	width: 80upx; 
	font-size: 28upx;
	color: #fff;
	background: #1890FF; 
	padding: 10upx 20upx;
	text-align: center;
	border-radius: 10upx;
	margin: 0 auto;
}

 

缓存数据修改

var _self;
import cache from '@/common/cache.js';
export default{
	data(){
		return{
			header:{}
		}
	},
	onLoad() {
		_self = this
	},
	onShow() {
		var header = cache.getCache('header')
		_self.header = header
		_self.$set(_self.header,'X-USER-ID','1')
		_self.$set(_self.header,'X-ACCESS-TOKEN','666')
		cache.setCache('header',_self.header)
	},
	methods:{
		
		
	}
}

 

发布时间:2022/02/23

发表评论