1 Star 0 Fork 56

SolarisNeko/vue-devtools

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
vue1-test.html 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
<html>
<body>
<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>
<script src="https://unpkg.com/[email protected]/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>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/SolarisNeko/vue-devtools.git
[email protected]:SolarisNeko/vue-devtools.git
SolarisNeko
vue-devtools
vue-devtools
main

搜索帮助