Vue中动态修改head标签的title及mate


1、安装

npm install vue-meta --save

2、引用  main.js

import Meta from 'vue-meta'
Vue.use(Meta)

3、动态修改   APP.vue

import {indexData} from './api/index'

data () {
    return {
      extension:'',
    }
  },

metaInfo(){//nuxt.js中metaInfo==head
   return {
    title: this.extension.f_extension_title,
    meta: [
     {
       hid: "keywords",
       name: 'keywords',
       content: this.extension.f_extension_keywords
     },
     {
       hid: "description",
       name: 'description',
       content: this.extension.f_extension_description,
     }
   ]
},
  methods: {   
    getAllData(){
      this.$axios.get(indexData,{
          params:{
          p:'pc'
          }
      }).then((res)=>{
          if(parseInt(res.data.errCode)>=0){
              if(res.data.data){
                 this.extension=res.data.data.extension       
              }
          }
          else{
          
          }
      }).catch((err)=>{
          console.log(err )
      })
    },  
  },
 
 
  mounted(){
   this.getAllData()
 }


 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM