闪光灯相关代码

这个博客展示了如何使用Vue.js创建一个动态列表,包括添加、删除和存储应用程序列表到本地存储。通过`v-for`指令遍历列表并触发`@click`事件进行操作,同时利用`uni.setStorageSync`和`uni.getStorageSync`进行数据持久化。此外,还包含了输入验证和模态对话框来确认删除操作。
摘要由CSDN通过智能技术生成

 

<template>
	<view class=" ">

		<view class="flex align-center   w-100 mx-4 my-5" v-for="(item,index) in appList" @click="del(index)"> {{item}}
		</view>


		<input type="text" value="" v-model="appname" />
	<button @click="add"> add</button>
		<button @click="save">save</button>
	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				time: '',
				index: 4,
				appList: [],
				appname: ''
			}
		},
		onLoad() {


			// this.testList()
			// this.testtime()
			// this.testStore()
			this.init()
		},
		methods: {
			
			init(){
					let bb = uni.getStorageSync('appList')
					if (bb){
						this.appList = JSON.parse(bb)
					}
			},

			add() {
				
				if (this.appname == '') return 
				if(this.isAppNameInList(this.appname)) return 
				console.log(this.appname)
				this.appList.push(this.appname)
				this.appname = ''
			},
			save() {
				uni.setStorageSync('appList', JSON.stringify(this.appList))
			},

			del(e) {
				console.log(e)
				uni.showModal({
					title: '是否删除',
					content: this.appList[e],

					success: res => {
						if (res.confirm) {
							console.log('click confi')
							this.appList.splice(e, 1)
							console.log("now is " + JSON.stringify(this.appList))
						} else {
							console.log("click cancle")
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			
			isAppNameInList(name){
				if(this.appList.indexOf(name) != -1){
					return true
				}
				else {
					return false
				}
			},


			testStore() {
				let aa = uni.setStorageSync('appList', JSON.stringify(this.appList))

				let bb = uni.getStorageSync('appList')
				// console.log(bb)
			},



			testList() {
				let list1 = ['111', '222', '333']
				let id = '222'

				// console.log(list1.indexOf('22'))


				if (list1.indexOf(id) != -1) {
					console.log(' id in list ')
				}
			},
			testtime() {
				this.time = setInterval(() => {
					// console.log('xxx')

					if (this.index === 0) {
						clearInterval(this.time)
					} else if (this.index % 2 === 0) {
						console.log("open ")
					} else {
						console.log("close")
					}
					this.index = this.index - 1

				}, 1000)

			}

		}
	}
</script>

<style>
	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值