当前位置:网站首页>微信小程序使用vant weapp报错
微信小程序使用vant weapp报错
2022-06-30 07:57:00 【Dark_programmer】
微信小程序使用vant weapp报错
如果是按照【vant weapp】 来一步步走的,也许会遇到我遇到的错误。
我的踩坑,希望能够帮你解决问题。
错误一:构建错误
当按照vant weapp
快速上手的指引一步步走,到了步骤四 构建 npm 包
遇到了第一个坑。
这个报错其实是因为上一步配置packNpmRelationList
时的路径不准确的问题。
解决办法:
"packNpmRelationList": [
{
"packageJsonPath": "./package.json",
"miniprogramNpmDistDir": "./node_modules/"
}
]
如此即可构建成功
错误二:[“usingComponents”][“van-button”] 未找到
这是遇到的第二个坑,这个坑有点让人疑惑。明明是完全按照官方文档
来的,为什么
会出现问题呢?不信邪的我又前前后后重新创建了三四个小程序,重新走这个过程。无一例外,全部都是这个问题。
百度好久,google好久。看了好多相关文章,发现那些文章有一个共同点
:
npm 构建生成 miniprogram_npm
但是我仔细看了看我的小程序,确定没有这个文件
。为什么别人有,我却没有???是不是哪里出问题了???或者说流程颠倒
了???
想到这,准备参考
官方文档,然后适当的调整一下步骤流程。果然,成功了。
下面就是我安装使用成功的步骤。
我的安装流程
1. 重新创建项目
在创建项目这一步骤不再进行赘述
此时的目录结构
:
2. 初始化npm
前提是你已经安装了node
和npm
。
npm init -y
3. 安装插件
npm i @vant/weapp -S --production
4. 勾选npm & npm构建
注意:
如果有使用npm模块选项
,就进行勾选
,然后构建npm
如果没有也不用纠结
,直接构建npm
我这里就没有使用npm模块选项
这个选项
构建完成后,注意看项目的目录结构多了一个文件夹:
到了这,我们才有了别人有的文件夹。
5. 修改 project.config.json
{
...
"setting": {
...
"packNpmManually": true,
"packNpmRelationList": [
{
"packageJsonPath": "./package.json",
"miniprogramNpmDistDir": "./miniprogram/"
}
]
}
}
6. 引入组件
如果发现报错Error: module "miniprogram_npm/@vant/weapp/common/component.js" is not defined
,不要紧张,刷新一下即可。
你可以选择在app.json
引入,也可以在指定组件的json文件
里进行引入
我是在app.json
里引入:
"usingComponents": {
"van-button": "@vant/weapp/button/index"
}
7. 使用组件
<van-button type="default">默认按钮</van-button>
<van-button type="primary">主要按钮</van-button>
<van-button type="info">信息按钮</van-button>
<van-button type="warning">警告按钮</van-button>
<van-button type="danger">危险按钮</van-button>
8. “style”: “v2”
在 vant weapp官方文档给了这么一句:
将 app.json 中的
"style": "v2"
去除,小程序的新版基础组件
强行加上了许多样式,难以覆盖,不关闭将造成部分组件样式混乱。
所以看个人情况,是否要删除这一句~
边栏推荐
- Simple application of generating function
- 冰冰学习笔记:快速排序
- Halcon12+vs2013 C # configuration
- C. Fishingprince Plays With Array
- Deep learning - brnn and DRNN
- Final review -php learning notes 8-mysql database
- 深度学习——序列模型and数学符号
- Go 数据类型篇之字符串及底层字符类型
- ACM. Hj48 delete the node with the specified value from the one-way linked list ●●
- Final review -php learning notes 3-php process control statement
猜你喜欢
Use of nested loops and output instances
期末複習-PHP學習筆記3-PHP流程控制語句
Deep learning -- using word embedding and word embedding features
November 22, 2021 [reading notes] - bioinformatics and functional genomics (Section 5 of Chapter 5 uses a comparison tool similar to blast to quickly search genomic DNA)
Deep learning - residual networks resnets
right four steps of SEIF SLAM
2021-10-27 [WGS] pacbio third generation methylation modification process
25岁,从天坑行业提桶跑路,在经历千辛万苦转行程序员,属于我的春天终于来了
November 9, 2020 [wgs/gwas] - whole genome analysis (association analysis) process (Part 2)
November 22, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5, section 4, hidden Markov model)
随机推荐
Hit the industry directly | the flying propeller launched the industry's first model selection tool
HelloWorld
Intersection of two lines
期末複習-PHP學習筆記3-PHP流程控制語句
ACM. Hj48 delete the node with the specified value from the one-way linked list ●●
你了解IP协议吗?
Fishingprince Plays with Array
November 16, 2021 [reading notes] - macro genome analysis process
2022 Research Report on China's intelligent fiscal and tax Market: accurate positioning, integration and diversity
Deep learning -- recurrent neural network
6月底了,可以开始做准备了,不然这么赚钱的行业就没你的份了
Deep learning vocabulary representation
Final review -php learning notes 2-php language foundation
342 maps covering exquisite knowledge, one of which is classic and pasted on the wall
At the end of June, you can start to make preparations, otherwise you won't have a share in such a profitable industry
全栈最全性能测试理论-总结
C. Fishingprince Plays With Array
Deep learning -- feature point detection and target detection
Deloitte: investment management industry outlook in 2022
深度学习——词汇表征