由于公司项目需求,我这儿计划的是把后台服务api以文件读写的方法存在本地(项目仍是用的Vue),怎样引进cordova以及树立cordova我这儿就省掉了。android手机

怎样运用

import { coeslint标准rdovaReadFijson格式le } from '@/utils/cordovaplugins'
//deviceready加载结束 才能访问cordova
documeapplicationnt.addEventListener('devicercordova口罩eady', () => {
cordocordova口罩vaReadFile()
}, false)

corcordova官网dovaplandroid是什么手机牌子ugins.jsappointmeESLintnt 封装的读写东jsonp西js 大约approve便eslint文档是读写文件操作,假定没有访问到文件cordova口罩 就创eslint报错建并写入,访问到直接就读取。

Cordova Android读写文件操作插件运用——cordova-plugin-file

ESLint官网得知 装备
<preference namcordova结构e="AndroidPersistentFileLappearanceocation" value="Internal" />设备的耐久化文件在安卓/data/data/<packagcordova下载eId>目录json解析下。

/* eslint-disablcordova打包e */
//装备文件名
conESLintst SETTING_FILE_NAcordova插件ME = "json解析json是什么意思setting.json"
const SETTIAndroidNG_FILE_CONTENT = JSON.stringify({
api: process.env.VUE_APP_BASE_API
})
/**
*@desc 写入文件
*@path /djsonobjectata/data/appId/file/file/config
*@jsonauthor Bob
*json格式怎样翻开@date 2021/04/28 19:07:31
*/
function createWriter(fileEntry, content) {
fileEntry.crcordova装置方位eateWriter(function (fileWrcordova打包iter) {
//文件写入成功
fileWricordova结构ter.onwriteeESLintnd = function () {
console.log("Successful file wandroid平板电脑价格rite...");
};
//文件写入失利
fileWriter.onerror = function (e) {
console.log("Failed file write: " + e.toSapproachtring());
};
//写jsonobject入文件
fileWriter.write(content)
})
}
/APP**
*@desc 读取文件
*@path /data/data/appId/file/fileandroid平板电脑价格/config
*@author Bob
*@datcordova插件e 202android手机1/04/28 19:09:54
*/
functieslint关闭onjsonobject readFile(fileEntry) {
fileEnteslint装备ry.file(function (fappstoreilapprovee)eslint装备 {
constandroid下载 reader = new FileReader()
readeslint关闭er.onloadend = functcordova下载ion () {
console.log("file read success:" + this.result);
}
reader.readAsText(file)
})
}
/**
*@desc 判别装备eslint装备cordova装置方位件是否存在
*@author Bob
*@date 202cordova装置方位1/04/28 19:27:26
*/
functionjson格式怎样翻开 settjsonpingFileIsExist(dirEntry, fileName) {
return new Promise((resolve, reject) => {
dirEntry.gappstoreetFile(fileName, {eslint语法create: false,app装置下载 exclusive: false}, function () {
resolve(true)
}, function ()eslint vue {
resolve(false)
})
})
}
/**
*@desc 创立装备文件
*@author Bob
*@date 2021/04APP/28 19:40:05
*/
funcordova官网ction createSettingFile(dirEntry, fileName, content) {
dirEntry.getFile(fileName, {createCordova: true, exclusiveeslint插件: fandroidstudio装置教程alse}, functcordova插件开发ion (fappearileEntry) {
createWriter(fileEntry, content)
}, funjson格式ction () {
ceslint标准onsole.log(fileName + "创立失利"appearance)Cordova
})
}
/**
*@desc 读取装备文件内容
*@author Bob
*@date 2021/04/28 19:48:15
*/
function readSettingFile(dirEntry, fileNaappleme) {
dirEntjson格式ryappointment.AndroidgetFile(fjsonileName, {create: fjsonobjectalse, exclusive: feslint怎样读alse}, functionjson解析 (fileEntry) {
readFile(fileEntry)
}, feslint怎样读unction () {
conseslint文档ole.log(fileName + "读取失利")
}Cordeslint装备ova)
}
export function corandroid下载dovaRecordova结构adFile () {
window.requestFileSystemandroid平板电脑价格(LocalFappleileSystem.PERSISTEajson文件是干什么的ppstoreNT, 0, function (fs){
fs.root.getDirectory('coeslint关闭nfig', {create: true}, async function(dirEntandroid平板电脑价格ry) {
//是否存在
const isExist = await settingFileandroid是什么手机牌子IsExist(dirEnjson是什么意思tcordova插件开发ry, SETTIAPPNG_FILE_NAME)
ifjson转map(!isExijsonst) {
createSettingFile(dirEntry, SETTING_FILE_NAME, SETTING_FILE_CONTENT)
} else {
readSettingFile(dirEntry, SETTING_FILE_NAME)
}
}, functandroid的drawable类ion () {
console.log("configappearance文件夹创立失利")
})
}, function (eslint文json格式怎样翻开) {
consocordova下载le.lcordova下载og("文件空间读取失利!json"application)
})
}

工作截图appearance

  • 文件读取成功

Cordova Android读写文件操作插件运用——cordova-plugin-file

  • 文件写入成功

Cordova Android读写文件操作插件运用——cordova-plugin-file