欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue項目如何安裝引入使用Vant

 更新時間:2024年10月17日 10:19:32   作者:SuperYiY  
Vant是一個專為移動端設計的輕量級組件庫,自2017年開源以來,提供了Vue2、Vue3及多平臺版本支持,安裝Vant時需要注意版本兼容問題,Vue3項目應安裝最新版Vant3,而Vue2項目則需安裝Vant2,安裝錯誤時,需卸載后重新安裝正確版本

前言

Vant 是一個輕量、可靠的移動端組件庫,于 2017 年開源。

目前 Vant 官方提供了 Vue 2 版本、Vue 3 版本和微信小程序版本,并由社區(qū)團隊維護 React 版本和支付寶小程序版本

Vue3安裝

npm install vant --save 

安裝為Vant的最新版,與Vue3適配;而是vue2項目需指定版本號為v2,否則會出錯

若出錯需要卸載 npm uninstall vant ,重新安裝

Vue2安裝

@ 指定最新的版本號

npm i vant@latest-v2 -S

main引入

在main.js文件中

1、全局全部引入:

import Vant from 'vant';
import 'vant/lib/index.css';
Vue.use(Antd);

// 根據本地localStorage存儲的當前語言類型,切換不同語言
import zhCN from 'vant/es/locale/lang/zh-CN'
import enUS from 'vant/es/locale/lang/en-US'
let lang = localStorage.getItem('lang') || 'zh_CN'
if (lang === 'en') {
  Locale.use('en-US', enUS)
} else {
  Locale.use('zh-CN', zhCN)
}

2、全局按需引入

  • 在src目錄創(chuàng)建plugins文件夾
  • 文件夾中創(chuàng)建vant.js文件做引入操作,
import Vue from 'vue'
// 在這里引入你所需的組件
import {
    Button,
    Cell,
    CellGroup,
    Icon
    // 。。。
} from 'vant'

// 按需引入UI組件
Vue.use(Button)
Vue.use(Cell)
Vue.use(CellGroup)
Vue.use(Icon)
	// 。。。
  • 將這個文件在man.js內引入
import Vue from 'vue'
import App from './App.vue'
import '@/plugins/vant'

// 其他操作...

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')

簡單使用

例子:vant折疊面板

        <div class="result-list">
          <van-row class="list-status">
            <van-col span="12"><span class="status-name"></span></van-col>
            <van-col span="3"><span class="status-name">列名1</span></van-col>
            <van-col span="3"><span class="status-name">列名2</span></van-col>
            <van-col span="3"><span class="status-name">列名3</span></van-col>
            <van-col span="3"><span class="status-name">列名4</span></van-col>
          </van-row>
          <div class="list-content">
            <van-collapse v-model="activeNames" :accordion="true">
              <van-collapse-item
                class="content-item"
                :name="item.schoolClassId"
                v-for="(item, index) in list"
                :key="index"
              >
                <template #right-icon>
                  <van-icon
                    class="item-icon"
                    :name="
                      activeNames == item.schoolClassId ? 'arrow-down' : 'arrow'
                    "
                    @click.native="showDetail = true"
                  />
                </template>
                <template slot="title">
                  <van-row
                    class="item-title"
                    @click.stop.prevent="onclickItem(item)"
                  >
                    <van-col span="2">
                      <div class="list-item-title">
                        <img
                          class="title-icon"
                          src="../../assets/images/xxx.png"
                          alt="icon"
                        />
                      </div>
                    </van-col>
                    <van-col span="10">
                      <div class="list-item-title de-list-title-big">
                        {{ item.className }}
                      </div>
                    </van-col>
                    <van-col span="3">
                      <div class="list-item-title">{{ item.notSubmitted }}</div>
                    </van-col>
                    <van-col span="3">
                      <div class="list-item-title">{{ item.positiveNum }}</div>
                    </van-col>
                    <van-col span="3">
                      <div class="list-item-title">
                        {{ item.positivePercentage }}
                      </div>
                    </van-col>
                    <van-col span="3">
                      <div class="list-item-title success-result">
                        {{ item.totalNumber }}
                      </div>
                    </van-col>
                  </van-row>
                </template>
                <div class="item-detail" v-if="showDetail">
                  <van-row>
                    <van-col span="6">
                      <div class="item-content">下拉內容1</div>
                      <div class="item-date">
                        {{ item.content }}
                      </div>
                    </van-col>
                    <van-col span="6">
                      <div class="item-content">下拉內容2</div>
                      <div class="item-date">
                        {{ item.content }}
                      </div>
                    </van-col>
                    <van-col span="6">
                      <div class="item-content">下拉內容3</div>
                      <div class="item-date">
                        {{ item.content }}
                      </div>
                    </van-col>
                    <van-col span="6">
                      <div class="item-content">下拉內容4</div>
                      <div class="item-date">
                        {{ item.content }}
                      </div>
                    </van-col>
                  </van-row>
                </div>
              </van-collapse-item>
            </van-collapse>
          </div>
        </div>

這里是引用

<style lang="less" scoped>
.result-list {
  min-height: 520px;
  padding: 17px;
  background-color: #c2e2ff;
  position: relative;
}
.list-status {
  float: right;
  height: 24px;
  width: 100%;
  font-size: 12px;
  text-align: start;
  margin-right: 20px;
  /* line-height: 12px; */
  color: RGBA(0, 0, 0, 0.4);
}

// 整個底部列表
.list-content {
  clear: both;
  // border: 1px solid red;
}
// 整個item(包括title和detail)
.content-item {
  margin-bottom: 10px;
  border-radius: 10px;
  overflow: hidden;
}
.item-icon {
  align-self: center;
}
// 每一項的item的title
.item-title {
  // border: 1px solid red;
  text-align: start;
  font-size: 14px;
  font-weight: 500;
  color: #f36292;
}
.list-item-title {
  // border: 1px solid yellow;
  height: 36px;
  line-height: 36px;
  position: relative;
}
.title-icon {
  width: 20px;
  height: 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
// 每一項的item的detail
.item-detail {
  // border: 1px solid red;
  padding-top: 10px;
  text-align: center;
  .item-content {
    font-size: 12px;
    font-weight: 400;
    color: RGBA(0, 0, 0, 0.4);
  }
  .item-date {
    margin-top: 10px;
    color: #f36292;
  }
  .van-col:nth-child(4) .item-date {
    color: #9ba7b0;
  }
}
</style>

總結

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • 一文詳解Vue Router的使用和路由守衛(wèi)

    一文詳解Vue Router的使用和路由守衛(wèi)

    Vue Router 是 Vue.js 的官方路由庫,用于在 Vue 應用中實現單頁面應用(SPA)的客戶端路由,以下是 Vue Router 的詳細介紹,包括基本概念、配置、路由導航以及高級用法,感興趣的小伙伴跟著小編一起來看看吧
    2024-08-08
  • 學習Vue組件實例

    學習Vue組件實例

    本篇文章給大家分享了Vue實例的相關內容以及重要知識點,對此有興趣的朋友可以跟著學習參考下。
    2018-04-04
  • vue2.0開發(fā)入門筆記之.vue文件的生成和使用

    vue2.0開發(fā)入門筆記之.vue文件的生成和使用

    本篇文章主要介紹了vue2.0開發(fā)入門筆記之.vue文件的生成和使用 ,非常具有實用價值,需要的朋友可以參考下
    2017-09-09
  • 用vue的雙向綁定簡單實現一個todo-list的示例代碼

    用vue的雙向綁定簡單實現一個todo-list的示例代碼

    本篇文章主要介紹了用vue的雙向綁定簡單實現一個todo的示例代碼,具有一定的參考價值,有興趣的可以了解一下
    2017-08-08
  • vue router中mode history、base的作用說明

    vue router中mode history、base的作用說明

    這篇文章主要介紹了vue router中mode history、base的作用說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • 在vue中created、mounted等方法使用小結

    在vue中created、mounted等方法使用小結

    這篇文章主要介紹了在vue中created、mounted等方法使用小結,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • vue cli3適配所有端方案的實現

    vue cli3適配所有端方案的實現

    這篇文章主要介紹了vue cli3適配所有端方案的實現,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-04-04
  • vue實現GitHub的第三方授權方法示例

    vue實現GitHub的第三方授權方法示例

    本文主要介紹了vue實現GitHub的第三方授權,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • vue-quill-editor 自定義工具欄和自定義圖片上傳路徑操作

    vue-quill-editor 自定義工具欄和自定義圖片上傳路徑操作

    這篇文章主要介紹了vue-quill-editor 自定義工具欄和自定義圖片上傳路徑操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • Vue.js 父子組件通信的十種方式

    Vue.js 父子組件通信的十種方式

    最近一直在做 Vue項目代碼層面上的優(yōu)化,寫文章是很easy的事情,今天小編給大家分享Vue.js 父子組件通信的十種方式,感興趣的的朋友跟隨小編一起看看吧
    2018-10-10

最新評論