Vue之整合bootstrap和JQuery

vue

整合bootstrap可参考:https://www.cnblogs.com/aoshuang/p/10691893.html

整合Jquery过程如下:

1、在package.json中添加jquery,如下图所示

"dependencies": {

"jsdom": "^16.2.0",

"location": "0.0.1",

"navigator": "^1.0.1",

"vue": "^2.5.2",

"vue-router": "^3.1.6",

"jquery": "^2.1.1",

"xmlhttprequest": "^1.8.0"

}

2、运行npm install ,安装jquery.

3、在webpack.base.conf.js文件中添加以下两个部分

\'use strict\'

var webpack = require("webpack")

const path = require(\'path\')

const utils = require(\'./utils\')

const config = require(\'../config\')

const vueLoaderConfig = require(\'./vue-loader.conf\')

function resolve (dir) {

return path.join(__dirname, \'..\', dir)

}

module.exports = {

context: path.resolve(__dirname, \'../\'),

entry: {

app: \'./src/main.js\'

},

output: {

path: config.build.assetsRoot,

filename: \'[name].js\',

publicPath: process.env.NODE_ENV === \'production\'

? config.build.assetsPublicPath

: config.dev.assetsPublicPath

},

resolve: {

extensions: [\'.js\', \'.vue\', \'.json\'],

alias: {

\'vue$\': \'vue/dist/vue.esm.js\',

\'@\': resolve(\'src\'),

}

},

module: {

rules: [

{

test: /\.vue$/,

loader: \'vue-loader\',

options: vueLoaderConfig

},

{

test: /\.js$/,

loader: \'babel-loader\',

include: [resolve(\'src\'), resolve(\'test\'), resolve(\'node_modules/webpack-dev-server/client\')]

},

{

test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,

loader: \'url-loader\',

options: {

limit: 10000,

name: utils.assetsPath(\'img/[name].[hash:7].[ext]\')

}

},

{

test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,

loader: \'url-loader\',

options: {

limit: 10000,

name: utils.assetsPath(\'media/[name].[hash:7].[ext]\')

}

},

{

test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,

loader: \'url-loader\',

options: {

limit: 10000,

name: utils.assetsPath(\'fonts/[name].[hash:7].[ext]\')

}

}

]

},

node: {

// prevent webpack from injecting useless setImmediate polyfill because Vue

// source contains it (although only uses it if it\'s native).

setImmediate: false,

// prevent webpack from injecting mocks to Node native modules

// that does not make sense for the client

dgram: \'empty\',

fs: \'empty\',

net: \'empty\',

tls: \'empty\',

child_process: \'empty\'

},

plugins: [

new webpack.ProvidePlugin({

jQuery: "jquery",

$: "jquery"

})

],

}

View Code

在文件第二行添加:

    var webpack = require("webpack")

在module.exports中结尾添加:

plugins: [

new webpack.ProvidePlugin({

jQuery: "jquery",

$: "jquery"

})

],

4、在main.js中添加import $ from \'jquery\',注意:一定要在bootstrap的引入之前

// The Vue build version to load with the `import` command

// (runtime-only or standalone) has been set in webpack.base.conf with an alias.

import Vue from \'vue\'

import App from \'./App\'

import router from \'./router.js\'

import $ from \'jquery\'

import \'./assets/bootstrap/css/bootstrap.min.css\'

import \'./assets/bootstrap/js/bootstrap.min\'

Vue.config.productionTip = false

/* eslint-disable no-new */

new Vue({

el: \'#app\',

router,

components: { App },

template: \'<App/>\',

})

5、npm run dev 重新编译运行,即可

以上是 Vue之整合bootstrap和JQuery 的全部内容, 来源链接: utcz.com/z/378058.html

回到顶部