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 中的 computed 和 watch 的區(qū)別
這篇文章分析 Vue 的 computed 和 watch 的區(qū)別,computed 用來(lái)監(jiān)控自己定義的變量,頁(yè)面上可直接使用。watch 是監(jiān)測(cè) Vue 實(shí)例上的數(shù)據(jù)變動(dòng),通俗地講,就是檢測(cè) data 內(nèi)聲明的數(shù)據(jù),需要的朋友可以參考一下2021-09-09詳解Electron中如何使用SQLite存儲(chǔ)筆記
這篇文章主要為大家介紹了Electron中如何使用SQLite存儲(chǔ)筆記示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11使用elementUI實(shí)現(xiàn)將圖片上傳到本地的示例
今天小編就為大家分享一篇使用elementUI實(shí)現(xiàn)將圖片上傳到本地的示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09如何解決Element-ui的el-table固定列后出現(xiàn)的表格錯(cuò)位問(wèn)題
這篇文章主要介紹了如何解決Element-ui的el-table固定列后出現(xiàn)的表格錯(cuò)位問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-09-09Vue+Typescript中在Vue上掛載axios使用時(shí)報(bào)錯(cuò)問(wèn)題
這篇文章主要介紹了Vue+Typescript中在Vue上掛載axios使用時(shí)報(bào)錯(cuò)問(wèn)題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下2019-08-08