zoukankan      html  css  js  c++  java
  • vuex mapState使用

    <template>
        <div>
            {{count}}
            <button @click="handleIncrease">+5</button>
            <button @click="handleDecrease">-5</button>
            <button @click="handleRouter">跳转到 HelloWorld3</button>
            <button @click="showRouter">展示路由</button>
        </div>
    </template>
    
    <script>
        import { mapState } from 'vuex'
        export default {
            name: 'HelloWorld2',
            computed: {
                //            count(){
                //                return this.$store.state.count;
                //            },
                //与上面效果一样
                ...mapState({
                    count: state => state.count
                })
            },
            methods: {
                handleIncrease() {
                    this.$store.commit('increase', 5);
                },
                handleDecrease() {
                    this.$store.commit('decrease', 5);
                },
                handleAsyncIncrease() {
                    this.$store.dispatch('asyncIncrease');
                },
                handleRouter() {
                    this.$router.push('/HelloWorld3');
                },
                showRouter() {
                    console.log(this.$router);
                    console.log(this.$router.push);
                }
            }
        };
    </script>
    
    <!-- Add "scoped" attribute to limit CSS to this component only -->
    <style scoped>
    
    </style>
    <template><div>{{count}}<button @click="handleIncrease">+5</button><button @click="handleDecrease">-5</button><button @click="handleRouter">跳转到 HelloWorld3</button><button @click="showRouter">展示路由</button></div></template>
    <script>import { mapState } from 'vuex'export default {name: 'HelloWorld2',computed: {//count(){//return this.$store.state.count;//},//与上面效果一样...mapState({count: state => state.count})},methods: {handleIncrease() {this.$store.commit('increase', 5);},handleDecrease() {this.$store.commit('decrease', 5);},handleAsyncIncrease() {this.$store.dispatch('asyncIncrease');},handleRouter() {this.$router.push('/HelloWorld3');},showRouter() {console.log(this.$router);console.log(this.$router.push);}}};</script>
    <!-- Add "scoped" attribute to limit CSS to this component only --><style scoped>
    </style>
  • 相关阅读:
    REST-framework快速构建API--生成Swagger接口文档
    Django后端彻底解决跨域问题
    Zabbix实战-简易教程--DB类--ClickHouse
    Django权限控制进阶
    django自定义rbac权限组件(二级菜单)
    jQuery事件委托
    model中的Meta类
    django中ModelForm解决多表单组合显示问题
    Django请求的生命周期
    AJAX
  • 原文地址:https://www.cnblogs.com/mengfangui/p/9149883.html
Copyright © 2011-2022 走看看