Created
June 21, 2017 15:07
-
-
Save bubnenkoff/69803fa030ea2a9ac5ffa88b32a83fbb to your computer and use it in GitHub Desktop.
Кнопки на Vue.JS калькулятор.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>test</title> | |
<script src="https://unpkg.com/vue"></script> | |
<style> | |
.active | |
{ | |
background:red; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="app"> | |
<todo></todo> | |
</div> | |
</body> | |
<script> | |
var bus = new Vue() | |
Vue.component('todo', { | |
template: ` | |
<div> | |
<div v-for="(name, index) in names"> | |
- <button @click="MyClick(name.n, index)" :class="{active: name.isClck}">{{name.n}} </button> | |
</div> | |
</div> | |
`, | |
data() { | |
return { | |
names: [ | |
{n: 'Dima', isClck: false}, | |
{n: 'Roma', isClck: false}, | |
{n: 'Masha', isClck: false}, | |
], | |
cname: '', | |
maxCnt: 2 | |
} | |
}, | |
methods : | |
{ | |
MyClick(name, index) | |
{ | |
this.cname = this.name; | |
this.names[index].isClck = !this.names[index].isClck; | |
console.log(this.maxCnt1); | |
} | |
}, | |
computed: { | |
maxCnt1() { | |
return this.names.filter(function(x) { return x.isClck }).length ; | |
} | |
} | |
}) | |
var app = new Vue({ | |
el: '#app', | |
data: { | |
message: 'Hello Vue!', | |
mycount: '', | |
name: 'Dima' | |
}, | |
methods: | |
{ | |
clickDo() | |
{ | |
this.mycount++; | |
console.log("doo: ", this.mycount); | |
}, | |
someinfo() | |
{ | |
console.log("fff"); | |
} | |
}, | |
created () { | |
bus.$on('hello', () => { console.log("weee"); bus.$emit("hellofromc"); }) | |
}, | |
watch : { | |
message: function() { | |
console.log("hello"); | |
} | |
} | |
}) | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment