Vue+webpack New Project Summary 1

Source: Internet
Author: User

Headers for header components display different headings depending on the page

The first step:

Initialize global variables in store

//Vuex through state management dataImport vue from ' Vue 'Import Vuex from' Vuex 'Vue.use (VUEX) const store=NewVuex.store ({state: {//PublicComm: {loading:false, Login: {memberid:‘‘, UserData:‘‘}, indexconf: {isfooter:false,//whether to show bottomIsback:false,//whether to show returnTitle: "//title}}} , mutations: {/*Modify the header information*/changeindexconf: (state, data)={object.assign (state.comm.indexConf, data)}, actions: {}, getter: {}}) exportdefaultStore

Step Two:

  Add a computed property to the head assembly so that the title can be changed dynamically

<template> <div class= "header" > <div class= "title" > <a @click = "GoBack" >< home</a> <span>{{title}}</span> </div> </div></template>< Script>Exportdefault{data:function () {              return {}        },        //calculated properties change dynamically based on the state of the storecomputed: {title:function () {                return  This. $store. State.comm.indexConf.title}, Isback:function () {                return  This. $store. State.comm.indexConf.isBack}}, methods: {goBack:function() {History.go (-1); }        }    }</script>

Step Three:

  Modify the title you need on each page (introduction to the header component)

default {        function  () {            return  {                title:' "        },        created () {              this. $store. Commit (' changeindexconf ', {                isfooter: False,                Isback:true,                title: 'components:{                    ')}, Comheader:header        }    }

Effect:

Vue+webpack New Project Summary 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.