1. 程式人生 > >nuxt.js實戰之引入jquery

nuxt.js實戰之引入jquery

head: {
    title: 'nuxt',
    meta: [
      { charset: 'utf-8' },
      { name: 'viewport', content: 'width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=0' },
      { hid: 'description', name: 'description', content: 'Nuxt.js project' }
    ],
    link: [
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
    ],
    script: [
      {
        src: 
'https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js' } ] }

nuxt.config.js中配置如上(有cdn的情況下適合使用這種方式)

如果沒有也可以使用如下方案:

首先安裝jquery 

npm install jquery --save

需要用到webpack,如果沒有需要安裝,nxut.config.js中的配置如下:

const webpack = require('webpack')
module.exports = {
  build: {
    plugins: [
      
new webpack.ProvidePlugin({ '$': 'jquery' }) ] }, plugins: [] }