代码拉取完成,页面将自动刷新
<html>
<body>
<script src="https://unpkg.com/vue@1.0.28/dist/vue.js"></script>
<script src="https://unpkg.com/vuex@1.0.1/dist/vuex.js"></script>
<div id="app"></div>
<script>
const store = new Vuex.Store({
state: {
counter: 0
},
mutations: {
INCREMENT: state => state.counter++,
DECREMENT: state => state.counter--,
SET_COUNTER: (state, value) => state.counter = value
}
})
Vue.component('data-test', {
template: `<div>
{{ bool }} {{ text }} {{ number }}
</div>`,
data () {
return {
bool: false,
text: 'hello world',
number: 0
}
}
})
Vue.component('vuex-test', {
template: `<div>
<div>{{ counter }} {{ isMoreThanTwo }}</div>
<div>
<button @click="$store.dispatch('INCREMENT')">+1</button>
<button @click="$store.dispatch('DECREMENT')">-1</button>
<button @click="$store.dispatch('SET_COUNTER', 0)">Reset</button>
</div>
</div>`,
computed: {
counter () {
return this.$store.state.counter
}
},
vuex: {
getters: {
isMoreThanTwo: state => state.counter > 2
}
}
})
Vue.component('event-test', {
template: `<div>
<button @click="$emit('foo', 'bar')">Emit event</button>
<button @click="$dispatch('foo', 'meow')">Dispatch event</button>
<button @click="$broadcast('foo', 'waf')">Broadcast event</button>
</div>`
})
new Vue({
el: '#app',
store,
template: `<div id="app">
<data-test></data-test>
<vuex-test></vuex-test>
<event-test @foo="onFoo"></event-test>
</div>`,
methods: {
onFoo (value) {
console.log(value)
}
}
})
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。