Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0.4] config中配置使用常量时无法生效 #5724

Closed
Kimbohn opened this issue Mar 17, 2020 · 7 comments
Closed

[2.0.4] config中配置使用常量时无法生效 #5724

Kimbohn opened this issue Mar 17, 2020 · 7 comments
Assignees

Comments

@Kimbohn
Copy link

Kimbohn commented Mar 17, 2020

问题描述

navigationBarTitleText 没有显示对应的值

import Taro, { PureComponent } from '@tarojs/taro'
import { View  } from '@tarojs/components'
import './index.less'

const BarTitle = '小程序名字'

class Index extends PureComponent {

  config: Taro.Config = {
    navigationBarTitleText: BarTitle ,
    navigationBarBackgroundColor: '#f06637',
    navigationBarTextStyle: 'white'
  }

  render() {
    return (
      <View className='container'>
        hello world
      </View>
    )
  }
}

复现步骤

  1. 定义常量BarTitle
  2. 配置config

期望行为

navigationBarTitleText 显示对应的值

报错信息

navigationBarTitleText 没有显示对应的值,显示‘WeChat’, 配置navigationBarBackgroundColor等其它属性也如此。

@taro-bot
Copy link

taro-bot bot commented Mar 17, 2020

CC @Chen-jj

@taro-bot
Copy link

taro-bot bot commented Mar 17, 2020

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

@shenghanqin
Copy link
Collaborator

打包后,这个config就到达index.json里面,也就是说,其实是不支持这么改的。如果你想后面再改页面标题,需要调用Taro.setNavigationBarTitle

Taro.setNavigationBarTitle({
          title: `主页`
        })

@taro-bot
Copy link

taro-bot bot commented Mar 18, 2020

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

@yyzclyang
Copy link

目前 taro 貌似不支持根据环境来定义不同的 config,比如测试和生产的 pages 是两个不同的数组,根据 process.env.NODE_ENV 来识别,编译直接报错

@shenghanqin
Copy link
Collaborator

我是想用dotenv来动态加载.env,里面是配置,这样的话,根据环境不同来加载不同的.env文件就好了。然后,这种.env可以保留在本地,github上都不用提交,防止配置泄露。

@yyzclyang
Copy link

如果我将 config 的配置放到一个 json 里面,然后读取这个 json 文件,将配置赋值给 app.tsxconfig ,编译会报错。
如果我想设置两个 app.tsx 文件入口,根据环境选择其中一个,貌似没暴露入口配置出来。
或者将 App 抽离成组件,在 app.tsx 引入后 render,这样也是无法正常编译的。

@taro-bot taro-bot bot removed the to be closed label Apr 2, 2020
@taro-bot taro-bot bot closed this as completed Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants