全局引入外部文件方法:
找到根目录下的nuxt.config.ts配置文件;然后如上图所示,在defineNuxtConfig配置对象下app选项节点下,head对象中即可配置全局需要的JS或CSS文件;
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
devtools: { enabled: true },
app: {
head: {
title: '',
meta: [],
link:[],
script: [
{ src: "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" }, {
src:"https://api.map.baidu.com/api?v=1.0&type=webgl&ak=ZNkgnHSRut2tWZD1XC85PEdpg3UFZTbQ"
}
]
},
},
plugins: [
{ src: '~/plugins/jquery.js' },
],
css: [
'/assets/css/main.scss','/public/css/animate.css'
],
})
提示:本地文件注意文件路引入规则;按照文件访问规定进行访问
传送门==》Nuxt3框架局部引入外部JS/CSS