代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<!--
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
-->
<style type="text/css">
.disabled {
color: orange;
}
</style>
</head>
<body>
<div id="app">
<div class="container-fluid">
<ul class="list-group">
<post v-for="item in posts" :posti="item"></post>
</ul>
</div>
</div>
<template id="post-template">
<li class="list-group-item">
<i class="glyphicon glyphicon-chevron-up" v-on:click="upvote" :class="{disabled: upvoted}"></i>
<span class="label label-primary">{{ votes }}</span>
<i class="glyphicon glyphicon-chevron-down" v-on:click="downvote" :class="{disabled: downvoted}"></i>
<a>{{ posti.title }}</a>
</li>
</template>
<script type="text/javascript">
Vue.component('post', {
template: "#post-template",
props: ['posti'],
data: function () {
return {
upvoted: false,
downvoted: false
};
},
methods:{
upvote:function(){
this.upvoted = !this.upvoted;
this.downvoted = false;
},
downvote:function(){
this.downvoted = !this.downvoted;
this.upvoted = false;
}
},
computed:{
votes:function(){
if(this.upvoted){
return this.posti.votes + 1;
}
else if(this.downvoted){
return this.posti.votes - 1;
}
else{
return this.posti.votes;
}
}
}
});
var vm = new Vue({
el: '#app',
data:{
posts: [{
title: "A post for our reddit demo starting at 15 votes",
votes: 15
},
{
title: "Try out the upvoting, it works, I promise",
votes: 53
},
{
title: "coligo is the bomb!",
votes: 10
}]
}
});
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。