新建的 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(); 不能放在最外层
好,现在运行就可以了。

被折叠的 条评论
为什么被折叠?



