1:npm install jquery

我們擁有十載網(wǎng)頁(yè)設(shè)計(jì)和網(wǎng)站建設(shè)經(jīng)驗(yàn),從網(wǎng)站策劃到網(wǎng)站制作,我們的網(wǎng)頁(yè)設(shè)計(jì)師為您提供的解決方案。為企業(yè)提供做網(wǎng)站、網(wǎng)站制作、微信開發(fā)、微信小程序、成都做手機(jī)網(wǎng)站、H5技術(shù)、等業(yè)務(wù)。無(wú)論您有什么樣的網(wǎng)站設(shè)計(jì)或者設(shè)計(jì)方案要求,我們都將富于創(chuàng)造性的提供專業(yè)設(shè)計(jì)服務(wù)并滿足您的需求。
2:在build文件夾下的webpack.base.conf.js進(jìn)行配置
(1)const webpack = require("webpack")
(2)在module.exports里面加入
???plugins: [
new webpack.optimize.CommonsChunkPlugin('common.js'),
? ? ? ? ? ? ?new webpack.ProvidePlugin({
jQuery:"jquery",
$:"jquery"
})
],
如圖
3:在需要用到j(luò)query的頁(yè)面引入
import $ from 'jquery';
第一步、在項(xiàng)目中npm安裝JQ
npm install jquery --save
第二步、檢查是否安裝成功
? ? ? ? ? ?在package.json中的dependencies查看是否含有jquery
第三步、配置JQ
? ? ? ? ? ?在vue.config.js中頂部寫入?const webpack = require('webpack')
? ? ? ? ? ?寫入后在configureWebpack中加入
第四步、重啟項(xiàng)目,引入成功
1、vue-cli webpack全局引入jquery
(1) 首先 npm install jquery --save (--save 的意思是將模塊安裝到項(xiàng)目目錄下,并在package文件的dependencies節(jié)點(diǎn)寫入依賴。)
(2)在webpack.base.conf.js里加入
1
var webpack = require("webpack")
(3)在module.exports的最后加入
1234567
plugins: [ new webpack.optimize.CommonsChunkPlugin('common.js'), new webpack.ProvidePlugin({ jQuery: "jquery", $: "jquery" })]
(4) 在main.js 引入就ok了 (測(cè)試這一步不用也可以)
1
import $ from 'jquery'
(5)然后 npm run dev 就可以在頁(yè)面中直接用$ 了.
一 .引入swiper(全局,局部)
方法一:全局引入,也是最暴力的,但是也是有好處壞處(同時(shí)加載,但是不能保證同時(shí)下載)
link href="" rel="stylesheet"script src=""/script12
組件中可以直接使用的swiper了
_initSwiper() { ? ? ? ?const container = this.$refs.swiper; ? ? ? ?const config = {
? ?effect: 'coverflow',
? ?slidesPerView: 'auto',
? ?centeredSlides: true,
? ?initialSlide: this.activeIndex,
? ?loop: true,
? ?autoplay: 1000,
? ?speed: 1000,
? ?coverflow: {
? ? ?rotate: 0,
? ? ?stretch: -30,
? ? ?depth: 100,
? ? ?modifier: 0.7,
? ? ?slideShadows: false,
? ?},
?}; ? ?this.mySwiper = new Swiper(container, config);
}1234567891011121314151617181920
2.方法二:main.js 中
import '../node_modules/swiper/dist/css/swiper.min.css';import 'swiper';12
執(zhí)行上面的_initSwiper()的方法 即可
3.方法三:局部的引入的,有時(shí)只想的單個(gè)組件中使用某一個(gè)的庫(kù),方法如下
section ref="swiper" class="swiper-container"
div class="swiper-wrapper"
div class="demo swiper-slide" v-for="item in colorList" :style="`backgroundColor:${item}`"/div
/div/sectionscript
let swiperAsync = import('swiper') //引入的swiper.js(node_modules)的方法
export default {
data(){ ? ? ?return {
?colorList: ['red', 'yellow', 'gray', 'pink']
}
},
methods: {
async _initSwiper() { ? ? ? ?let Swiper = await swiperAsync; //異步加載的
?const container = this.$refs.swiper; //ref='swiper'
?const config = { ?//swiper的參數(shù)配置
? ?effect: 'coverflow',
? ?slidesPerView: 'auto',
? ?centeredSlides: true,
? ?initialSlide: this.activeIndex,
? ?loop: true,
? ?autoplay: 1000,
? ?speed: 1000,
? ?coverflow: {
? ? ?rotate: 0,
? ? ?stretch: -30,
? ? ?depth: 100,
? ? ?modifier: 0.7,
? ? ?slideShadows: false,
? ?},
?}; ? ? ? ?this.mySwiper = new Swiper(container, config);
},
},
mounted(){ ? ? ?this._initSwiper();
}
}/scriptstyle lang="scss" scoped
/*@import '../assets/styles/swiper.min.css'; !*靜態(tài)資源的文件*!*/
@import '../../node_modules/swiper/dist/css/swiper.min.css';/style12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
二 引入的jquery的方法
全局的方法
script src=""/script1
組件中可以直接使用的 ‘$’的方法
局部的方法:
npm install jquery -D1
需要使用的組件中引入
import $ from 'jquery'1
標(biāo)題名稱:vue中引入jquery,vue中引入css文件
網(wǎng)址分享:http://chinadenli.net/article3/dsiggis.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、品牌網(wǎng)站建設(shè)、云服務(wù)器、網(wǎng)站排名、定制網(wǎng)站、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)