DevEco Studio在模拟器中改变运行的 ets 文件

新建的 ets 文件,想让 previewer 里运行这个 ets 文件怎么做。

entry\src\main\ets\entryability\EntryAbility.ets

windowStage.loadContent('pages/Index', (err) => {

将 'pages/Index' 改为你的 ets 路径

src/main/resources/base/profile/main_pages.json 配置白名单,不然运行了也是白屏

{
  "src": [
    "pages/Index"
  ]
}

添加你的 ets 文件路径

改完main_pages.json文件后提示

core configuration attributes have changed since last project sync.A project sync may be necessary for the IDE to work properly.                                     Sync Now

点击 Sync Now,不然不生效。

或是点击

File 菜单=》Sync and Refresh Project

如果只是为运行官方文档测试用例可以用引入组件方式

@Entry
@Component
struct BuilderDemo {
  @Builder
  showTextBuilder() {
    // @Builder装饰此函数,使其能以链式调用的方式配置并构建Text组件
    Text('Hello World')
      .fontSize(30)
      .fontWeight(FontWeight.Bold)
  }

  @Builder
  showTextValueBuilder(param: string) {
    Text(param)
      .fontSize(30)
      .fontWeight(FontWeight.Bold)
  }

  build() {
    Column() {
      // 无参数
      this.showTextBuilder()
      // 有参数
      this.showTextValueBuilder('Hello @Builder')
    }
  }
}

上面的用例复制下来新建个文件叫 Demo.ets,复制进去

做一些改动

1、删除 @Entry

2、struct BuilderDemo 变为 export default struct BuilderDemo

3、在 index.ets 入口文件中引入组件,

import Demo from './Demo';

RelativeContainer() { Demo(); }

注意:因为只能有一个根组件,所以 Demo(); 不能放在最外层

好,现在运行就可以了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值