vue.js整合mint-ui里的輪播圖實(shí)例代碼
初始化vue項(xiàng)目
npm install -g vue-cli vue init webpack demo # 中間會(huì)讓你選npm yarn 等來(lái)安裝依賴,我選的是yarn,因?yàn)樗煨?/pre>
安裝mint-ui
yarn add mint-ui
mint-ui裝好了,還要配置一下babel,方法跟著mint-ui的官方文檔來(lái)配置就可以了
下面是我配置好的 .babelrc 文件,啟動(dòng)的時(shí)候會(huì)報(bào)跟es2015相關(guān)的錯(cuò),裝一下 babel-preset-es2015 就好了
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"stage-2",
["es2015", { "modules": false }]
],
"plugins": [["component", [
{
"libraryName": "mint-ui",
"style": true
}
]],"transform-vue-jsx", "transform-runtime"],
"env": {
"test": {
"presets": ["env", "stage-2", "es2015"],
"plugins": ["transform-vue-jsx", "transform-es2015-modules-commonjs", "dynamic-import-node"]
}
}
}
集成
打開創(chuàng)建的vue項(xiàng)目demo,在src里找到 components/HelloWorld.vue 文件,然后將內(nèi)容換成下面內(nèi)容
<template>
<div>
<mt-swipe :auto="2000">
<mt-swipe-item v-for="item in items" :key="item.id">
<a :href="item.href" rel="external nofollow" >
<img :src="item.url" class="img"/>
<span class="desc"></span>
</a>
</mt-swipe-item>
</mt-swipe>
</div>
</template>
<script>
import {Swipe, SwipeItem} from 'mint-ui'
import 'mint-ui/lib/style.css'
export default {
components: {
'mt-swipe': Swipe,
'mt-swipe-item': SwipeItem
},
data () {
return {
items: [{
title: '你的名字',
href: 'http://google.com', url: 'http://localhost:8080/static/img1.png'
}, {
title: '我的名字',
href: 'http://baidu.com', url: 'http://localhost:8080/static/img2.png'
}]
}
}
}
</script>
<style scoped>
img {
width: 100%;
}
.mint-swipe {
height: 218px;
}
.desc {
font-weight: 600;
opacity: .9;
padding: 5px;
height: 20px;
line-height: 20px;
width: 100%;
color: #fff;
background-color: gray;
position: absolute;
bottom: 0;
}
</style>
找兩張圖片,名字分別是 img1.png , img2.png , 放在demo項(xiàng)目的static里,然后啟動(dòng)項(xiàng)目
npm run dev
打開瀏覽器:http://localhost:8080/
注意
1.如果發(fā)現(xiàn)文字都是居中的
可以找到文件 App.vue 把里面的居中css代碼去掉就好了
1.如果頁(yè)面有內(nèi)邊距
設(shè)置一下 body 的樣式 margin: 0 auto;
1.頁(yè)面里用的時(shí)候,必須要給類樣式一個(gè)高度,要不然圖片不出來(lái) .mint-swipe { height: 218px; }
總結(jié)
以上所述是小編給大家介紹的vue.js整合mint-ui里的輪播圖實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
使用vue-cli4.0快速搭建一個(gè)項(xiàng)目的方法步驟
這篇文章主要介紹了使用vue-cli4.0快速搭建一個(gè)項(xiàng)目的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12
極速上手 VUE 3 teleport傳送門組件及使用語(yǔ)法
teleport 傳送門組件,提供一種簡(jiǎn)潔的方式,可以指定它里面的內(nèi)容的父元素,也就是說(shuō)teleport 中的內(nèi)容允許我們控制在任意的DOM中,使用簡(jiǎn)單,對(duì)VUE 3 teleport傳送門相關(guān)知識(shí)感興趣的朋友一起看看吧2021-10-10
針對(duì)Vue路由history模式下Nginx后臺(tái)配置操作
這篇文章主要介紹了針對(duì)Vue路由history模式下Nginx后臺(tái)配置操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-10-10
詳解Vue 普通對(duì)象數(shù)據(jù)更新與 file 對(duì)象數(shù)據(jù)更新
本篇文章主要介紹了詳解Vue 普通對(duì)象數(shù)據(jù)更新與 file 對(duì)象數(shù)據(jù)更新 ,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-04-04
Nuxt 嵌套路由nuxt-child組件用法(父子頁(yè)面組件的傳值)
這篇文章主要介紹了Nuxt 嵌套路由nuxt-child組件用法(父子頁(yè)面組件的傳值),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11

