uni-app引入vant
发布时间
阅读量:
阅读量
安装vant:
# 通过 npm 安装
npm i @vant/weapp -S --production
# 通过 yarn 安装
yarn add @vant/weapp --production
安装后出现@vant

复制dist文件夹:

前往新建的wxcomponents:粘贴,并改名vant:

所以vant里面是:

App.vue引入样式:

pages.json: 引入组件

index.vue 使用组件:
<template>
<view>
<view>Vant Weapp组件</view>
<van-button block type="default">默认按钮</van-button>
<van-button block type="primary">主要按钮</van-button>
<van-button block type="info">信息按钮</van-button>
<van-button block type="warning">警告按钮</van-button>
<van-button type="danger">危险按钮</van-button>
</view>
</template>
<script>
</script>
<style>
</style>

这个时候特别注意:
如果使用微信小程序开发,main.js为:
import App from './App'
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
// #endif
// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
const app = createSSRApp(App)
return {
app
}
}
// #endif

如果是PC开发,main.js为:(加入了vant)
// #ifndef VUE3
import App from './App'
import Vue from 'vue'
import './uni.promisify.adaptor'
import Vant from 'vant'
import 'vant/lib/index.css'
Vue.use(Vant)
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
// #endif
// #ifdef VUE3
import { createSSRApp } from 'vue'
import App from './App'
import Vant from 'vant'
import 'vant/lib/index.css'
export function createApp() {
const app = createSSRApp(App)
app.use(Vant)
return {
app
}
}
// #endif

最后展示:

全部评论 (0)
还没有任何评论哟~
