uniapp 在app端如何选择本地json文件,不用uni.chooseImage方法
时间: 2023-12-09 14:03:06 浏览: 40
在uniapp中,可以使用uni.request方法来获取本地的json文件数据。具体步骤如下:
1. 在本地项目中创建json文件,例如data.json,并将数据写入该文件。
2. 在app端的vue文件中,使用uni.request方法获取该json文件的数据。
```
uni.request({
url: '/static/data.json', //json文件的路径
success: res => {
console.log(res.data) //获取到的json数据
},
fail: err => {
console.log(err)
}
})
```
3. 在manifest.json文件中配置本地资源路径,使其可以被uni.request方法获取到。
```
{
"pages":[
{
"path":"pages/index/index",
"style":{
"navigationBarTitleText":"首页"
}
}
],
"window":{
"backgroundTextStyle":"light",
"navigationBarBackgroundColor":"#fff",
"navigationBarTitleText":"uni-app",
"navigationBarTextStyle":"black"
},
"tabBar":{
"color":"#666",
"selectedColor":"#007aff",
"backgroundColor":"#fff",
"borderStyle":"black",
"list":[
{
"pagePath":"pages/index/index",
"text":"首页",
"iconPath":"/static/tabbar/home.png",
"selectedIconPath":"/static/tabbar/home_selected.png"
}
]
},
"networkTimeout":{
"request":10000,
"downloadFile":10000
},
"onReachBottomDistance":50,
"enablePullDownRefresh":true,
"usingComponents":{},
"debug":true,
"res":{
"root":"static" //配置本地资源路径
}
}
```
通过以上步骤,就可以在app端选择本地json文件了。