zoukankan      html  css  js  c++  java
  • vue+webpack新项目总结1

    头部组件的  标题  根据不同的页面显示不同的标题

    第一步:

      在store 里面初始化全局变量

    // vuex 通过状态管理数据
    import Vue from 'vue'
    import Vuex from 'vuex'
    Vue.use(Vuex)
    
    const store = new Vuex.Store({
      state: {
        // 公共
        comm: {
          loading: false,
          login: {
            memberId: '',
            userData: ''
          },
          indexConf: {
            isFooter: false, // 是否显示底部
            isBack: false,  // 是否显示返回
            title: '' // 标题
          }
        }
      },
      mutations: {
          /*修改header的信息*/
        changeIndexConf: (state, data) => {
          Object.assign(state.comm.indexConf, data)
        },
      },
      actions: {
    
      },
      getter: {
    
      }
    })
    
    export default store

    第二步:

      在头部组件中添加计算属性,使得title可以动态变化

       import Header from '../components/header'
        
        export default{
            data: function () {
                return {
                    title:'Markets'
                }
            },
            created () {//属性已绑定,dom未生成,一般在这里进行ajax处理以及页面初始化处理
                //改变store里面的变量
                  this.$store.commit('changeIndexConf', {
                    isFooter: false,
                    isBack: true,
                    title: 'Markets'
                  })
            },
            components:{
                comHeader:Header
            }
        }

    效果:

    有关于watch,computed,methods 的区别和联系:

      参考文章:https://zhuanlan.zhihu.com/p/30584492

  • 相关阅读:
    css-css背景
    css-概述和选择器
    html-补充
    html-示例代码
    html-表格和列表
    html-表单
    html-常用标签
    html- 头部元素
    html-介绍
    SQLAlchemy-对象关系教程ORM-连接,子查询
  • 原文地址:https://www.cnblogs.com/rachelch/p/7744775.html
Copyright © 2011-2022 走看看