代碼如下所示
- 發現了點擊按鈕1可以更新title內容,但是點擊按鈕2卻無法更新title內容。這個究竟是爲什麼呢?
<template>
<view class="container">
<text>{{title}}</text>
<button type="default" @click="changeTitle1">改變標題內容按鈕1</button>
<button type="default" @click="changeTitle2">改變標題內容按鈕2</button>
</view>
</template>
<script>
export default{
data(){
return{
title : "這個是標題",
}
},
methods:{
changeTitle1(){
this.title = "改變標題1";
},
//可以發現下面這個執行了success方法,但是調用this賦值卻無法改變內容
changeTitle2(){
uni.setStorage({
key: 'storage_key',
data: 'hello',
success: function () {
this.title = "改變標題2";
console.log('changeTitle2------success');
}
});
},
}
}
</script>
<style>
.container{
display: flex;
flex-flow: column;
}
</style>