代码如下所示 - 发现了点击按钮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>