<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-rc.2/js/materialize.min.js"></script>
<link rel="import" href="paper-checkbox.html">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
</head>
<style>
body {
font-family: Lato;
}
.demo {
max-width: 600px;
margin: auto;
}
</style>
<body>
<div id="vue-app">
<h3>paper-checkbox</h3>
<hr/>
<div class="demo">
<h5>Demo</h5>
<table>
<tr>
<td>Simple</td>
<td>
<div class="row">
Which script are you coding?
<paper-checkbox v-model="whatAreYouCoding.php">PHP</paper-checkbox>
<paper-checkbox v-model="whatAreYouCoding.laravel">Laravel</paper-checkbox>
<paper-checkbox v-model="whatAreYouCoding.vue">VUE</paper-checkbox>
</div>
</td>
</tr>
<tr>
<td>
{{whatAreYouCoding}}
</td>
</tr>
<tr>
<td>Adding click event</td>
<td>
Which script are you eating?
<paper-checkbox @click="clicked" v-model="whatAreYouEating.apple">Apple</paper-checkbox>
<paper-checkbox @click="clicked" v-model="whatAreYouEating.banana">Banana</paper-checkbox>
<paper-checkbox @click="clicked" v-model="whatAreYouEating.orange">Orange</paper-checkbox>
</td>
</tr>
<tr>
<td>
{{whatAreYouEating}}
</td>
</tr>
</table>
</div>
</body>
<script>
new Vue({
el: '#vue-app',
data:{
whatAreYouCoding:{
php:true,
laravel:true,
vue:true
},
whatAreYouEating:{
apple: true,
banana: true,
orange: true
}
},
methods: {
clicked: function(e) {
console.log(e.target.id);
}
}
})
</script>
</html>
<script>
Vue.component('paper-checkbox', {
template: '<div> \
<label> \
<input type="checkbox" \
class="filled-in" \
v-bind:id="_id" \
v-bind:checked="value" \
@click="click($event)"/> \
<span><slot></slot></span> \
</label> \
</div>',
props: {
value: {
type: Boolean,
default: false
},
id: {
type: String,
default: null
}
},
computed: {
_id: function () {
if (this.id != null) return this.id;
return Math.random().toString(36).substr(2);
}
},
methods: {
click: function (e) {
this.$emit('input', e.target.checked);
this.$emit('click', e);
}
}
})
</script>