5 Star 1 Fork 0

wangzhiweik/shop-system

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
communication1.html 2.25 KB
一键复制 编辑 原始数据 按行查看 历史
xiefy0066 提交于 2017-12-09 11:11 . 登录评论
<!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>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/jason_wangzhiwei/shop-system.git
git@gitee.com:jason_wangzhiwei/shop-system.git
jason_wangzhiwei
shop-system
shop-system
master

搜索帮助