.js文件:
import dataStorage from '@ohos.data.storage';
import ability_featureAbility from '@ohos.ability.featureAbility';
export default {
data: {
path : '',
title : '123',
},
onInit() {
},
InitDataStorage(){
ability_featureAbility.getContext().getOrCreateLocalDir((err, value) => {
this.path = value;
console.log("fileIO begin")
console.info("path = " + JSON.stringify(this.path))
})
dataStorage.getStorage(this.path + '/mystore', function (err, storage) {
if (err) {
console.info("Failed to get the storage. path: " + this.path + '/mystore');
return;
}
storage.putSync('startup', 'auto');
storage.flushSync();
})
},
GetDataStorage(){
let that = this;
dataStorage.getStorage(this.path + '/mystore', function (err, storage){
if (err) {
console.info("Failed to get the storage. path: " + path + '/mystore');
return;
}
storage.get('startup', 'default', function(err, value) {
if (err) {
console.info("Failed to get the value of startup with err: " + err);
return;
}
console.info("The value of startup is " + value);
console.info("The type of value is " + typeof(value))
that.title = value;
})
})
},
}
欢迎评论区讨论