Vue实现简单的按钮选中和取消功能
效果图:html代码:<!doctype html><html lang="en"><head><title>Title</title><!-- Required meta tags --><meta charset="utf-8"><meta name...
·
效果图:
html代码:
<!doctype html>
<html lang="en">
<head>
<title>Title</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="../../bootstrap/css/bootstrap.min.css">
</head>
<body>
<div id="apps">
<my-button title="黄瓜"></my-button>
<my-button title="冬瓜"></my-button>
<my-button title="苦瓜"></my-button>
</div>
</body>
<script src="vue.min.js"></script>
</html>
js代码:
<script>
//组件开发:注册全局组件
Vue.component("my-button", {
props: ['title'],
data() {
return {
sty: false
}
},
methods: {
colors() {
// this.as = true;
this.sty = !this.sty;
}
},
template: `<button @click="colors"
:class="[sty?'active':'']"
class="btn btn-outline-danger btn-lg btn-block">{{title}}
</button>`
})
let vm = new Vue({
el: '#apps'
})
</script>
更多推荐
已为社区贡献2条内容
所有评论(0)