taro 引入js_Taro引入vant Weapp的方法

Taro(V2.0.5)中引入Vant Weapp,(需下载资源到项目中:大小约322KB)

需如下几步:

1.在/src/components下新建文件夹vant-weapp

2.在github上找到Vant-weapp下载文件包,将对应的dist文件夹下内容复制到新建的vant-weapp文件夹下。

(下载vant-weapp方式,编辑器终端输入:git clone https://github.com/youzan/vant-weapp.git )

3.在Pages或components对应文件的config.usingComponents中,配置每个页面所需要的组件。(注:无法在app.js中进行全局注册组件。)

例:

config = {

usingComponents: {

"van-icon": "../../components/vant-weapp/icon/index"

}

}

4.在使用Vant-weapp组件后,taro会自动将相应的组件复制一份到dist/components下,而Vant-weapp的组件还依赖工具库/src/components/vant-weapp/wxs,该工具库taro不会自动复制到dist中。所以,我们需要在/config/index.js文件下的config配置中新增copy.patterns,让其在编译时,自动复制到dist对应目录下。

copy: {

patterns: [

{

from: 'src/components/vant-weapp/wxs/',

to: 'dist/components/vant-weapp/wxs/'

}

],

options: {}

}

5.对Taro进行重新编译(例:npm run build:weapp)

*由于Vant-weapp的样式使用的单位是px,所以会被taro编译成rpx。可以通过修改/config/index.js文件中的config.mini.postcss.pxtransform.selectorBlackList不让其单位转换。

pxtransform: {

enable: true,

config: {},

selectorBlackList: [

/^.van-.*?$/,

]

}

注:Taro编译器无法自动将用到组件的.wxs文件移动到/dist相应目录下(**开发者工具会报错**)。

需在config配置中新增copy.patterns配置

例子:

copy: {

patterns: [

{

from: 'src/components/vant-weapp/wxs/',

to: 'dist/components/vant-weapp/wxs/'

},

{

from: 'src/components/vant-weapp/sticky',

to: 'dist/components/vant-weapp/sticky'

},

{

from: 'src/components/vant-weapp/tabs',

to: 'dist/components/vant-weapp/tabs'

}

],

options: {}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值