vue.js整合mint-ui里的輪播圖實例代碼
初始化vue項目
npm install -g vue-cli vue init webpack demo # 中間會讓你選npm yarn 等來安裝依賴,我選的是yarn,因為它快些
安裝mint-ui
yarn add mint-ui
mint-ui裝好了,還要配置一下babel,方法跟著mint-ui的官方文檔來配置就可以了
下面是我配置好的 .babelrc 文件,啟動的時候會報跟es2015相關的錯,裝一下 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項目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項目的static里,然后啟動項目
npm run dev
打開瀏覽器:http://localhost:8080/
注意
1.如果發(fā)現(xiàn)文字都是居中的
可以找到文件 App.vue 把里面的居中css代碼去掉就好了
1.如果頁面有內(nèi)邊距
設置一下 body 的樣式 margin: 0 auto;
1.頁面里用的時候,必須要給類樣式一個高度,要不然圖片不出來 .mint-swipe { height: 218px; }
總結
以上所述是小編給大家介紹的vue.js整合mint-ui里的輪播圖實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關文章
分析 Vue 中的 computed 和 watch 的區(qū)別
這篇文章分析 Vue 的 computed 和 watch 的區(qū)別,computed 用來監(jiān)控自己定義的變量,頁面上可直接使用。watch 是監(jiān)測 Vue 實例上的數(shù)據(jù)變動,通俗地講,就是檢測 data 內(nèi)聲明的數(shù)據(jù),需要的朋友可以參考一下2021-09-09使用elementUI實現(xiàn)將圖片上傳到本地的示例
今天小編就為大家分享一篇使用elementUI實現(xiàn)將圖片上傳到本地的示例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-09-09如何解決Element-ui的el-table固定列后出現(xiàn)的表格錯位問題
這篇文章主要介紹了如何解決Element-ui的el-table固定列后出現(xiàn)的表格錯位問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-09-09Vue+Typescript中在Vue上掛載axios使用時報錯問題
這篇文章主要介紹了Vue+Typescript中在Vue上掛載axios使用時報錯問題,本文給大家介紹的非常詳細,具有一定的參考借鑒價值 ,需要的朋友可以參考下2019-08-08