<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>