Nuxt.js服務(wù)器渲染SSR 修改head信息 配置axios body內(nèi)引入js

修改head信息

head: {
    title: '我是標(biāo)題啊',
    htmlAttrs: {
      lang: 'en'
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1' },
      { hid: 'keywords', name: 'keywords', content: '哈哈,嘿嘿,乎乎' },
      { hid: 'description', name: 'description', content: '啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ]
     script: [
       //head添加js
       { src: 'https://s9.#/z_stat.php?id=123456789&web_id=321456987' }
     ]
  },

修改頁(yè)面title


async asyncData({ $axios,params,app }) {
    app.head.title = '體語(yǔ)文章資訊-'
    // console.log(articleConten)
    return {}
  },

配置axios代理

modules: ['@nuxtjs/axios'],
axios: {
    prefix: '/api/',
    proxy: true
},

proxy: {
    '/api/': {
        target: 'https://sys.new-obj.com/',
        pathRewrite: {
            '^/api/': ''
        }
    }
},

頁(yè)面加入第三方j(luò)s

default.vue

import {seo} from '~/static/js/assist'
export default {
    mounted(){
        seo();
    }
}

assist.js

export function seo() {
    let script = document.createElement('script')
    script.src = 'https://s9.#/z_stat.php?id=123456789&web_id=321456987'
    script.language = 'javascript'
    document.body.appendChild(script)

    document.dispatchEvent(new Event('render-event')) 
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容