vue实现引入本地json的方法分析
作者:佑之以航 时间:2023-07-02 16:32:14
本文实例讲述了vue实现引入本地json的方法。分享给大家供大家参考,具体如下:
当前需要使用的组件:
import data from './test.json'
export default{
data(){
return{
userinform: ''
}
},
mounted(){
this.userinform = data
}
}
test.json就是普通json格式就可以了!然后完美解决!
后台服务器请求json方式:
this.$http.get('url').then(response => {
//succces callback
var data = response.body;
}, response => {
// error callback
alert('连接失败!')
});
附:VUE解析json展示列表页示例
<div class="padding">
<div id="app">
<ol>
<li v-for="site in sites">
{{ site.name }}
</li>
</ol>
</div>
</div>
<script src="https://cdn.bootcss.com/vue/2.2.2/vue.min.js"></script>
<script>
function getJson(url,func){ $.ajax({ type:'get', url:url, dataType: 'json', success: function(data){ if (data.code==0){ var a = data.data.list;func(a); }else{ alert("接口调用失败"); } }, error: function(data){ alert(JSON.stringify(data)); } }); }
$(function(){ var url = "http://www.test.com/index.php?s=/shop/list/"; getJson(url,pushDom); });
function pushDom(data){ var vm = new Vue({
el: '#app',
data: {
sites: data
}
})}
</script>
希望本文所述对大家vue.js程序设计有所帮助。
来源:https://www.cnblogs.com/yzyh/p/7422989.html
标签:vue,json
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python实现抠图给证件照换背景源码
2022-06-21 04:39:38
Python模块、包(Package)概念与用法分析
2022-09-02 13:06:22
![](https://img.aspxhome.com/file/2023/7/117277_0s.png)
Django restful framework生成API文档过程详解
2021-08-10 16:37:16
![](https://img.aspxhome.com/file/2023/5/76005_0s.png)
Python requests模块用法详解
2022-02-09 23:00:13
go语言实现并发网络爬虫的示例代码
2024-01-31 07:45:35
![](https://img.aspxhome.com/file/2023/5/109715_0s.png)
最简单的tab切换实例代码
2023-08-22 08:38:59
![](https://img.aspxhome.com/file/2023/6/56006_0s.jpg)
Python爬虫小技巧之伪造随机的User-Agent
2023-11-02 21:32:41
Python下的常用下载安装工具pip的安装方法
2021-08-31 05:05:35
一文带你了解Go语言中的指针和结构体
2024-04-25 15:26:20
![](https://img.aspxhome.com/file/2023/4/134104_0s.png)
详解Oracle修改字段类型方法总结
2024-01-20 22:40:26
剖析Python的Tornado框架中session支持的实现代码
2022-12-06 17:53:13
数据库查询排序使用随机排序结果示例(Oracle/MySQL/MS SQL Server)
2024-01-18 20:14:13
Django中login_required装饰器的深入介绍
2023-08-22 09:18:28
sql 百万级数据库优化方案分享
2024-01-20 13:20:24
go日志库中的logrus
2023-07-21 13:48:02
使用python-cv2实现Harr+Adaboost人脸识别的示例
2022-03-16 01:05:10
![](https://img.aspxhome.com/file/2023/3/68473_0s.png)
python检测远程端口是否打开的方法
2022-01-28 01:45:19
php版银联支付接口开发简明教程
2023-11-24 00:27:41
oracle 触发器 学习笔记
2009-05-24 19:57:00
详解Python中heapq模块的用法
2022-01-15 05:58:35
![](https://img.aspxhome.com/file/2023/7/89447_0s.png)