老莫的笔记本  
  
查看: 943|回复: 1

Remax 中 使用 微信组件的坑

[复制链接]

662

主题

878

帖子

5139

积分

超级版主

Rank: 8Rank: 8

积分
5139
发表于 2021-3-2 16:38:18 | 显示全部楼层 |阅读模式
本帖最后由 周大胖子 于 2021-3-2 16:45 编辑

先上个官方文档链接:https://remaxjs.org/guide/basic/custom-component  [我就是照着这个做的 然后满世界报错]
好了 先谈成功方法:
1.在项目中安装微信组件的包 :
       npm install --save weui-miniprogram

2.引入且使用【可以照着上方的链接里面复制,也可以复制我下面的】

  1. import * as React from 'react';
  2. import { View , Button   } from 'remax/one';  


  3. import Cells from "weui-miniprogram/miniprogram_dist/cells/cells";
  4. import Cell from 'weui-miniprogram/miniprogram_dist/cell/cell';

  5. import 'weui-miniprogram/miniprogram_dist/weui-wxss/dist/style/weui.wxss';
  6. import Dialog from 'weui-miniprogram/miniprogram_dist/dialog/dialog';

  7. class Trademark extends React.Component{
  8.     constructor(props) {
  9.         super(props);
  10.         this.tapDialogButton = this.tapDialogButton.bind(this);
  11.         this.doDialog = this.doDialog.bind(this);

  12.         this.state={
  13.             dialogShow: false,
  14.             showOneButtonDialog: false,
  15.             buttons: [{text: '取消'}, {text: '确定'}],
  16.         }
  17.     }      

  18.     tapDialogButton(e)
  19.     {
  20.         console.log(e)
  21.         this.setState({
  22.             dialogShow: false
  23.         })
  24.     }
  25.     doDialog(){
  26.         console.log('进来了')
  27.         this.setState({
  28.             dialogShow: true
  29.         })
  30.     }

  31. // 坑爹 官方文件复制粘贴过来后 凉了,且各种实验 都不行 除非删了重新解压缩

  32.     render(){
  33.         return(
  34.             <View className="textH3">
  35.                 商标
  36.                 <Button className="tmListBtn"> 商标注册1</Button>
  37.                 <Button className="tmListBtn"> 商标注册2</Button>
  38.                 <Button className="tmListBtn"> 商标注册3</Button>


  39.                 <View>
  40.                     <Cells title="带说明的列表项">
  41.                     <Cell value="标题文字" footer="说明文字"></Cell>
  42.                     <Cell>
  43.                         <View>标题文字(使用slot)</View>
  44.                         <View slot="footer">说明文字</View>
  45.                     </Cell>
  46.                     </Cells>
  47.                 </View>
  48.                
  49.                 <Button className="tmListBtn" onTap={this.doDialog} > 弹出框测试 </Button>

  50.                 <Dialog title="test" show={this.state.dialogShow} bindbuttontap={this.tapDialogButton} buttons={this.state.buttons}>
  51.                     <View> 弹出框 </View>
  52.                 </Dialog>

  53.             </View>
  54.         );
  55.     }

  56. }

  57. export default Trademark;
复制代码


3.关掉cmd, 把dist 文件夹删了[嗯 没错 删掉] ,然后 重新打包 npm run dev wechat

4. 进微信开发者工具里面看效果:

  没报错很好结束,如果报错:

[] ENOENT: no such file or directory, open 'E:\phpstudy_pro\remax\here\dist\wechat\project.config.json'
Error: ENOENT: no such file or directory, open 'E:\phpstudy_pro\remax\here\dist\wechat\project.config.json'

  出现这个解决方法:
    在 dist/wecaht 文件夹内新建一个【 project.config.json 】 就这个文件,里面内容可以复制下面的:
  1. {
  2.   "description": "项目配置文件",
  3.   "packOptions": {
  4.     "ignore": []
  5.   },
  6.   "setting": {
  7.     "urlCheck": false,
  8.     "es6": true,
  9.     "enhance": false,
  10.     "postcss": true,
  11.     "preloadBackgroundData": false,
  12.     "minified": true,
  13.     "newFeature": false,
  14.     "coverView": true,
  15.     "nodeModules": false,
  16.     "autoAudits": false,
  17.     "showShadowRootInWxmlPanel": true,
  18.     "scopeDataCheck": false,
  19.     "uglifyFileName": false,
  20.     "checkInvalidKey": true,
  21.     "checkSiteMap": true,
  22.     "uploadWithSourceMap": true,
  23.     "compileHotReLoad": false,
  24.     "useMultiFrameRuntime": true,
  25.     "useApiHook": true,
  26.     "useApiHostProcess": false,
  27.     "babelSetting": {
  28.       "ignore": [],
  29.       "disablePlugins": [],
  30.       "outputPath": ""
  31.     },
  32.     "enableEngineNative": false,
  33.     "bundle": false,
  34.     "useIsolateContext": true,
  35.     "useCompilerModule": true,
  36.     "userConfirmedUseCompilerModuleSwitch": false,
  37.     "userConfirmedBundleSwitch": false,
  38.     "packNpmManually": false,
  39.     "packNpmRelationList": [],
  40.     "minifyWXSS": true
  41.   },
  42.   "compileType": "miniprogram",
  43.   "libVersion": "2.15.0",
  44.   "appid": "wx9f6afd0fc5e708d4",
  45.   "projectname": "eee",
  46.   "cloudfunctionTemplateRoot": "",
  47.   "watchOptions": {
  48.     "ignore": []
  49.   },
  50.   "debugOptions": {
  51.     "hidedInDevtools": []
  52.   },
  53.   "scripts": {},
  54.   "condition": {
  55.     "plugin": {
  56.       "list": []
  57.     },
  58.     "game": {
  59.       "list": []
  60.     },
  61.     "gamePlugin": {
  62.       "list": []
  63.     },
  64.     "miniprogram": {
  65.       "list": []
  66.     }
  67.   }
  68. }
复制代码


完工; 重新打开下微信开发者工具,就行了 ;




回复

使用道具 举报

662

主题

878

帖子

5139

积分

超级版主

Rank: 8Rank: 8

积分
5139
 楼主| 发表于 2021-3-2 16:43:08 | 显示全部楼层
本帖最后由 周大胖子 于 2021-3-2 16:46 编辑

这个坑点:
1. 说找不到路径,我以为是引入路径问题,谁知道是没有这个文件 ;
2. 这个文件 我最后也不知道怎么出的,就这么莫名奇妙出来了 ,然后 再次打包失败又报错了, 幸好我之前存了成功的,一对比 果然少个文件,复制粘贴就可以用了 ;
3. 很多时候,这个报错是消不掉的, 就算不引入组件,如果之前报错,这里也跑不动,必须删除dist 整个文件夹,然后不引入组件重新打包,才能继续跑;
4. 官方给的某个github 上示例,居然是 引入 componts中 加入这些,我照着搬了没用,结果发现它居然把版本 1.几的,拿来当2.几的 示例,操 误导我一天;5. 我花了很长的时间,照着原生的小程序引入 ,捣鼓config.js 和json 其实没必要,最后就动了一个文件
这个坑爬出来 耗费了我 整整两天,不容易啊 -.-
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表