时间:2021-07-23 07:38:37 | 栏目:vue | 点击:次
首先导入
<script type="text/javascript" src="/island/stage/js/vue.min.js"></script>
html样式:
<div id="main-content" class="wrap-container zerogrid"> <article id="news_content" v-for="item in items"> <div class="col-1-2 right"> <img :src="item.coverimage"/><!--img标签与src之间需要有空格--> </div> <div class="col-1-2 left"> <a class="art-category left" href="#" rel="external nofollow" rel="external nofollow" >{{item.releasetime}}</a> <div class="clear"></div> <div class="art-content"> <h2>{{item.title}}</h2> <div class="info"> <a href="#" rel="external nofollow" rel="external nofollow" >{{item.author}}</a> </div> <div class="line"></div> <p>{{item.content}}</p> <a v-bind:href="['/island/stage/newscontent.html?id='+item.id]" rel="external nofollow" class="more">阅读全文</a> <!--属性数据绑定以及拼接--> </div> </div> </article> <!-- 循环结束(新闻) --> </div>
js部分:
var vm = new Vue({ el: '#main-content', data: { items : [] }, //end data created:function(){ $.post("/island/stage/queryOneAllNews.do",{"categoryid":parseInt(categoryid)},function(data){ vm.items = data; });//end post } //created }); //end vue
注意:返回的json数组 并不需要JSON.stringify(data) 转成json字符串 items 这里需要的是json对象
当然 官网上推荐的是使用axios npm这种方式。