vue引入jq

http://blog.csdn.net/Zhooson/article/details/76578735


以前习惯性是引用jQuery,bootstrap。。。库,但是不会引用,怎么办?

npminstallswiper--save-dev (或者 npminstalljquery -D)

1

一 .引入swiper(全局,局部)

方法一:全局引入,也是最暴力的,但是也是有好处坏处(同时加载,但是不能保证同时下载)

组件中可以直接使用的swiper了

_initSwiper() {constcontainer =this.$refs.swiper;constconfig = {          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 =newSwiper(container, config);}

2.方法二:main.js 中

import'../node_modules/swiper/dist/css/swiper.min.css';import'swiper';

执行上面的_initSwiper()的方法 即可

3.方法三:局部的引入的,有时只想的单个组件中使用某一个的库,方法如下

letswiperAsync = import('swiper')//引入的swiper.js(node_modules)的方法exportdefault{  data(){return{        colorList: ['red','yellow','gray','pink']      }    },    methods: {      async _initSwiper() {letSwiper = await swiperAsync;//异步加载的constcontainer =this.$refs.swiper;//ref='swiper'constconfig = {//swiper的参数配置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 =newSwiper(container, config);      },    },    mounted(){this._initSwiper();    }  }/*@import '../assets/styles/swiper.min.css'; !*静态资源的文件*!*/@import'../../node_modules/swiper/dist/css/swiper.min.css';

二 引入的jquery的方法

全局的方法

组件中可以直接使用的 ‘$’的方法

局部的方法:

npm install jquery -D

需要使用的组件中引入

import $ from 'jquery'

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,009评论 19 139
  • 在线阅读 http://interview.poetries.top[http://interview.poetr...
    前端进阶之旅阅读 114,858评论 24 450
  • 秋风起,稻穗黄。这个时候 ,放眼望去,金黄金黄的稻穗沉甸甸的弯着腰,一阵秋风吹过,莎莎作响。然今年屋后的那片...
    81d1aa263da清风阅读 715评论 5 3
  • "修炼了几千万年,一身铠甲护身,还是没能挡住敌人的食欲,倒是锁住了炉火的鲜味。"一个教师拿着一只螃蟹感叹到。...
    启夏来晚了阅读 170评论 0 0
  • 最后一次的温柔在我的世界里沉默
    然5阅读 215评论 0 0