鍍金池/ 問(wèn)答/HTML/ vue-cli讓頁(yè)面頭部的標(biāo)題隨著頁(yè)面的跳轉(zhuǎn)而變成相應(yīng)的頁(yè)面標(biāo)題

vue-cli讓頁(yè)面頭部的標(biāo)題隨著頁(yè)面的跳轉(zhuǎn)而變成相應(yīng)的頁(yè)面標(biāo)題

這個(gè)是首頁(yè)面 的標(biāo)題
clipboard.png

這個(gè)是商品列表頁(yè)面 但是標(biāo)題我想換掉
clipboard.png

header我是單獨(dú)一個(gè)組件寫(xiě)的
就是要怎么切換標(biāo)題

回答
編輯回答
真難過(guò)

在每個(gè)父組件(首頁(yè)、商品列表頁(yè))個(gè)設(shè)置一個(gè)headerTitle常量,然后傳值給子組件(Header)就可以了
代碼如下:

//這是父組件

<template>
  <div class="login">
    <Header :headTitle='headTitle'/>
    <div class='content-wrapper'></div>
  </div>
</template>

<script>
import Header from './Header'

export default {
  name: 'Login',
  data () {
    return {
      headTitle: 'Login'
    }
  },
  components: { Header }
}
</script>
//這是子組件

<template>
  <div class='header'>{{ title }}</div>
</template>

<script>
export default {
  name: 'Header',
  props: ['headTitle'],
  data () {
    return {
      title: this.headTitle
    }
  }
}
</script>
2017年10月4日 17:20