zoukankan      html  css  js  c++  java
  • vue

    1.store

    const state = {
      stageWidth: "large"
    };
    const mutations = {
      CHANGE_WIDTH: (state, str) => {
        state.stageWidth = str;
      }
    };
    const actions = {
      changeWidth({ commit }, data) {
        commit("CHANGE_WIDTH", data);
      }
    };
    
    //getters.js
    const getters = {
      stageWidth: state => state.app.stageWidth
    };
    
    

    2.App.vue

    <template>
        <div id="app">
            <router-view />
        </div>
    </template>
    
    <script>
    import { mapGetters } from 'vuex';
    export default {
        data() {
            return {
                fullWidth: document.documentElement.clientWidth
            };
        },
        name: 'App',
        computed: {
            ...mapGetters(['stageWidth'])
        },
        methods: {
            handleResize() {
                let that = this;
                that.fullWidth = document.documentElement.clientWidth;
                if (that.fullWidth < 768 && that.stageWidth == 'large') {
                    that.$store.dispatch('app/changeWidth', 'small');
                }
                if (that.fullWidth > 768 && that.stageWidth == 'small') {
                    that.$store.dispatch('app/changeWidth', 'large');
                }
            }
        },
        created() {
            if (this.fullWidth < 768 && this.stageWidth == 'large') {
                this.$store.dispatch('app/changeWidth', 'small');
            }
            if (this.fullWidth > 768 && this.stageWidth == 'small') {
                this.$store.dispatch('app/changeWidth', 'large');
            }
            window.addEventListener('resize', this.handleResize);
        },
        beforeDestroy: function() {
            window.removeEventListener('resize', this.handleResize);
        }
    };
    </script>
    
    
    

    3.使用

     <el-table-column label="操作" align="center" header-align="center" width="100" :fixed="stageWidth == 'small' ? false : 'right'">
              <template slot-scope="scope">
                   <el-button type="text" size="mini" @click="jumpToEdit(scope.row.pcid)">编辑</el-button>
                   <el-button type="text" size="mini"  @click="deleteProcess(scope.row)">删除</el-button>
              </template>
    </el-table-column>
    
  • 相关阅读:
    CSS样式—绝对定位(absolute)与相对定位(relative)的区别(图示)
    firefox与IE透明度(opacity)设置区别
    nopCommerce学习之架构(三)
    nopCommerce学习之程序包(四)
    Hadoop 部署
    nopCommerce学习之汉化(二)
    PetShop 首页
    nopCommerce学习之安装配置(一)
    C# 中ToString()的用法
    对象的当前状态使该操作无效
  • 原文地址:https://www.cnblogs.com/gggggggxin/p/14280640.html
Copyright © 2011-2022 走看看