爱编程爱分享,原创文章,转载请注明出处,谢谢!http://www.cnblogs.com/fozero/p/6170706.html javascript
一、经过Script引入Vuejs框架html
<script type="text/javascript" src="https://unpkg.com/vue@2.1.4/dist/vue.js"/>
二、实例化Vue并配置Vue选项 vue
var vm = new Vue({ el: '#app', data: { shops:'' }, created:function(){//实例建立时被调用 this.getShopList(); }, methods:{ getShopList:function(){//获取店铺列表 $.get(WEB_API_URL+"/Api/Shop",{ r:Math.random() },function(result){ // console.log(JSON.stringify(result)); if(result.errno==0){ $.each(result.data,function(index,item){ //数组对象添加imgurl元素 var img_url=shop_icons[Math.floor(Math.random()*shop_icons.length)]; item["imgurl"]=img_url; }); vm.shops = result.data; }else{ alert("服务器出错啦~"); } }); } } });
说明:java
选项中的el属性绑定页面中id为app的div编程
Vuejs框架提供一系列钩子函数 ,created方法在Vue实例建立时被调用数组
咱们全部的方法定义在methods选项中,这里咱们定义获取店铺列表的方法getShopList,而后在created方法中调用服务器
最后数据请求成功以后进行数据绑定app
三、使用v-for指定对列表渲染框架
<li v-for="shop in shops"> <a href="store_detail.html" v-bind:id="shop.ID" v-bind:baiduid="shop.baidu_id" v-bind:meituanid="shop.meituan_id"> <div class="left mend_img"> <img v-bind:src="shop.imgurl"/> </div> <div class="left name"> <h1>{{shop.shop_name}}</h1> <label>{{shop.shop_address}}</label> </div> <div class="clearfix"></div> </a> </li>
四、显示效果dom