您好,登錄后才能下訂單哦!
本篇內容主要講解“Vue項目中如何使用Bootstrap”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Vue項目中如何使用Bootstrap”吧!
Bootstrap需要依賴jQuery,所以引用Bootstrap之前要先引用jQuery,使用下面的命令引用jQuery:
npm install jquery --save
npm view jquery versions
可以使用下面的命令安裝:
npm install bootstrap --save
直接去Bootstrap下載bootstrap包,把下載好的文件放到src/assets目錄下面:
在build/webpack.base.conf.js文件的頂部添加下面的代碼:
const webpack=require("webpack")
在build/webpack.base.conf.js文件中,在整個配置對象的末尾增加plugins配置:
// 配置全局使用 jquery plugins: [ new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery", jquery: "jquery", "window.jQuery": "jquery" })]
build/webpack.base.conf.js完整代碼如下:
'use strict' const path = require('path') const utils = require('./utils') const config = require('../config') const vueLoaderConfig = require('./vue-loader.conf') const webpack=require("webpack") function resolve (dir) { return path.join(__dirname, '..', dir) } // const createLintingRule = () => ({ // test: /\.(js|vue)$/, // loader: 'eslint-loader', // enforce: 'pre', // include: [resolve('src'), resolve('test')], // options: { // formatter: require('eslint-friendly-formatter'), // emitWarning: !config.dev.showEslintErrorsInOverlay // } // }) 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: [ // 關閉eslint編碼規范驗證 // ...(config.dev.useEslint ? [createLintingRule()] : []), { 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' }, // 配置全局使用 jquery plugins: [ new webpack.ProvidePlugin({ $: "jquery", jQuery: "jquery", jquery: "jquery", "window.jQuery": "jquery" })] }
// 引入jQuery import $ from 'jquery' // 引用bootstrap import './assets/bootstrap-3.3.7-dist/css/bootstrap.css' import './assets/bootstrap-3.3.7-dist/js/bootstrap.js'
<template> <div> <p class="col-md-6"> <button class="btn btn-primary">測試按鈕</button> </p> </div> </template> <script> export default { name:"test", } </script>
運行效果:
到此,相信大家對“Vue項目中如何使用Bootstrap”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。