本文介绍了vue引入swiper插件,分享给大家,希望对大家有帮助
步骤一:安装vue,
$ npm install vue
步骤二:创建vue项目
# 全局安装 vue-cli $ npm install -g vue-cli $ cd my-project $ npm install $ npm run dev
上面这些就是安装好vue项目,最主要的就是下面的步骤
步骤三:下载好swiper相关的js和css,js放在static目录下,css放在assets目录下。
步骤四:
安装runtime:
终端命令:npm install babel-runtime
步骤五:
修改.eslintrc.js文件如下:
// http://eslint.org/docs/user-guide/configuring module.exports = { root: true, parser: 'babel-eslint', parserOptions: { sourceType: 'module' }, env: { browser: true, }, // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style extends: 'standard', // required to lint *.vue files plugins: [ 'html' ], // add your custom rules here 'rules': { // allow paren-less arrow functions 'arrow-parens': 0, // allow async-await 'generator-star-spacing': 0, // allow debugger during development 'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0 }, 'globals': { "Swiper": true } //这个地方是新加入的 全局注入 }
步骤六:在自己的vue文件中添加轮播图代码
<div v-on:mouseenter="stopPlay()" v-on:mouseleave="play()" class="swiper-container gallery-top swiper-container-horizontal"> <div class="swiper-wrapper"> <div v-for="value in lbt" class="swiper-slide swiper-slide-next" style="width: 100%; margin-right: 10px;" v-bind:style="{backgroundImage: 'url(' + value.imgs + ')'}"></div> </div> <div class="swiper-button-next swiper-button-white"></div> <div class="swiper-button-prev swiper-button-white swiper-button-disabled"></div> </div> <div class="swiper-container gallery-thumbs swiper-container-horizontal"> <div class="swiper-wrapper"> <div v-for="value in lbt" class="swiper-slide swiper-slide-next" style="margin-right: 10px;" v-bind:style="{backgroundImage: 'url(' + value.imgs + ')'}"></div> </div> </div>
import Swiper from '../../static/swiper-3.4.2.min.js' let galleryTop let galleryThumbs export default { name: 'main', data () { return { lbt: [ { 'imgs': '../static/product/lbt1.jpg' }, { 'imgs': '../static/product/lbt2.jpg' }, { 'imgs': '../static/product/lbt3.jpg' } ] } }, mounted () { this.lunbo() }, methods: { lunbo () { galleryTop = new Swiper('.gallery-top', { nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', spaceBetween: 10, grabCursor: true, initialSlide: 1, autoplayDisableOnInteraction: false }) galleryThumbs = new Swiper('.gallery-thumbs', { spaceBetween: 10, autoplay: 4000, initialSlide: 1, centeredSlides: true, slidesPerView: 'auto', touchRatio: 0.2, slideToClickedSlide: true, autoplayDisableOnInteraction: false, grabCursor: true }) galleryTop.params.control = galleryThumbs galleryThumbs.params.control = galleryTop }, stopPlay () { galleryTop.stopAutoplay() galleryThumbs.stopAutoplay() }, play () { galleryTop.startAutoplay() galleryThumbs.startAutoplay() } } }
@import url("../assets/swiper-3.4.2.min.css"); .gallery-top{ height:32rem; width:100%; } .gallery-thumbs{ height:20%; box-sizing:border-box; padding:10px 0; background: rgba(0, 0, 0, 0.4); cursor: pointer; } .gallery-thumbs .swiper-slide{ width:30%; height:6rem; opacity:0.3; } .gallery-thumbs .swiper-slide-active{ opacity:1; } .swiper-slide{ background-size: 100% 160%; -webkit-background-size: 100% 160%; }
这里还有一个很重要的问题,在模板里面设置背景图,写法应该是
v-bind:style="{backgroundImage: 'url(' + value.imgs + ')'}"
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持小牛知识库。
本文向大家介绍解决vue中使用swiper插件问题及swiper在vue中的用法,包括了解决vue中使用swiper插件问题及swiper在vue中的用法的使用技巧和注意事项,需要的朋友参考一下 Swiper简介 Swiper常用于移动端网站的内容触摸滑动。 Swiper是纯javascript打造的滑动特效插件,面向手机、平板电脑等移动终端。 Swiper能实现触屏焦点图、触屏Tab切换、触屏多
本文向大家介绍vue引入jq插件的实例讲解,包括了vue引入jq插件的实例讲解的使用技巧和注意事项,需要的朋友参考一下 今天做官网,把unslider做成指令,但是一直提示$(el).unslider() no a function,一开始我想复杂了,后来在网上看了很多帖子,大多数都是修改webpack.base.config.js,仔细尝试,网上确实是对的,尝试过程中,提醒大家最好把这3个加全,
本文向大家介绍vue 中swiper的使用教程,包括了vue 中swiper的使用教程的使用技巧和注意事项,需要的朋友参考一下 Install 在vue cli下的使用 npm install vue-awesome-swiper --save 在main.js中 在component.vue中 参考:https://github.com/surmon-china/vue-awesome-swip
怎么在Nuxt3项目中引入swiper插件? 在网上找到的教程几乎都是vue项目或nuxt2,多次在Nuxt3项目中尝试引入swiper一直失败,我的vue版本是3.4
本文向大家介绍vue中七牛插件使用的实例代码,包括了vue中七牛插件使用的实例代码的使用技巧和注意事项,需要的朋友参考一下 本文介绍了vue中七牛插件使用,我也正在学习,分享给大家,顺便留个笔记,废话不说了,如下: 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持呐喊教程。
本文向大家介绍vue使用video插件vue-video-player的示例,包括了vue使用video插件vue-video-player的示例的使用技巧和注意事项,需要的朋友参考一下 一、安装插件 二、配置插件 在main.js中全局配置插件 三、使用插件 在vue组件中的程序如下: 四、结果 结果如图所示: vue-video-player的npm社区地址:https://w
本文向大家介绍Vue框架里使用Swiper的方法示例,包括了Vue框架里使用Swiper的方法示例的使用技巧和注意事项,需要的朋友参考一下 下载swiper 首先使用npm 或者cnpm下载swiper 引入swiper 使用swiper mounted里面调用 注意 如果想要从后台请求图片放上去 new Swiper要写在网络请求成功的函数里面,否则不会出来数据。 slider组件的内容如下:
我试图在bootstrap-vue表中创建一个插槽,用自定义组件呈现任何布尔值。 所以我有一张简单的桌子 现在,如果我想以特定的方式呈现单个列,我必须使用插槽 它是有效的,因为我知道是一个布尔值。 我想概括这种行为,但我不能在模板中使用,也不能在模板上使用...这个想法是创建一个包含我所有布尔字段的数组并迭代它... 像这样的