Vue如何引用Vant组件

这里是Vant的官方文档https://youzan.github.io/vant-weapp/#/intro

 

第一步 使用终端安装Vant

npm i vant -S

第二步 使用终端安装babel-plugin-import(在编译过程中将 import 的写法自动转换为按需引入的方式)

npm i babel-plugin-import -D

第三步  在.babelrc文件中配置plugins(插件)

备注: 因为windows环境下一直找不到.babelrc文件,通过package.json配置过后结合楼主的方法,成功引入!感谢

"plugins": [
    "transform-vue-jsx",
    "transform-runtime",
    ["import", [{ "libraryName": "vant", "style": true }]]
  ],

 

 

第四步 按需要引入vant组件

 

 

第五步 HelloWorld.vue 实践

<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <van-button square type="primary">主要按钮</van-button>
  </div>
</template>

<script>

import Vue from 'vue';
import { Button } from 'vant';

Vue.use(Button);

export default {
  name: "HelloWorld",
  props: {
    msg: String,
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>

  

 

效果图:

 

end

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值