写给初学者的 HarmonyOS 教程 -- 状态管理(@State/@Prop/@Link 装饰器)

news2024/9/24 9:28:03

@State 装饰的变量,或称为状态变量,一旦变量拥有了状态属性,就和自定义组件的渲染绑定起来。当状态改变时,UI 会发生对应的渲染改变(类似 Compose 的 mutablestateof )。

@Prop 装饰的变量可以和父组件建立单向的同步关系。@Prop 装饰的变量是可变的,但是变化不会同步回其父组件。

@Lin k装饰的变量可以与其父组件中对应的数据源建立双向数据绑定。

@State 装饰器使用规则

@State变量装饰器说明
装饰器参数
同步类型不与父组件中任何类型的变量同步
允许装饰的变量类型Object、class、string、number、boolean、enum 类型,以及这些类型的数组。
类型必须被指定。
不支持 any,不支持简单类型和复杂类型的联合类型,不允许使用 undefined 和 null。
被装饰变量的初始值必须本地初始化

@State 装饰器使用场景

装饰简单类型的变量

@Entry
@Component
struct Index {
  @State count: number = 0;

  build() {
    Column() {
      Button() {
        Text(`click times: ${this.count}`).margin(20)
      }
      .onClick(() => {
        this.count += 1;
      })
      .width('100%')
    }
    .margin(20)
    .height('100%')
  }
}

当状态变量 count 改变时,查询到只有 Button 组件关联了它;执行 Button 组件的更新方法,实现按需刷新。

运行效果:
在这里插入图片描述

装饰 class 对象类型的变量

@State 除了可以装饰简单类型的变量以外,好可以装修 class 对象,比如,我们在代码里面定义一个 class 类:

class Model {
  public value: string;

  constructor(value: string) {
    this.value = value;
  }
}

@Entry
@Component
struct Index {
  @State count: number = 0;

  build() {
    Column() {
      MyComponent({ count: 1, increaseBy: 2 }).margin(20)
      MyComponent({ title: new Model('Hello, World 2'), count: 7 }).margin(40)
    }
    .width('100%')
  }
}

@Component
struct MyComponent {
  @State title: Model = new Model('Hello World');
  @State count: number = 0;
  private increaseBy: number = 1;

  build() {
    Column() {
      Text(`${this.title.value}`)
      Button(`Click to change title`).onClick(() => {
        // @State 变量的更新将触发上面的 Text 组件内容更新
        this.title.value = this.title.value === 'Hello ArkUI' ? 'Hello World' : 'Hello ArkUI';
      }).margin(20)

      Button(`Click to increase count=${this.count}`).onClick(() => {
        // @State 变量的更新将触发该 Button 组件的内容更新
        this.count += this.increaseBy;
      })
    }
  }
}

运行效果:

在这里插入图片描述

可以发现:第一个 MyComponent 内部状态的更改是不会影响第二个 MyComponent。

@Prop 装饰器使用规则

@Prop变量装饰器说明
装饰器参数
同步类型单向同步:对父组件状态变量值的修改,将同步给子组件@Prop装饰的变量,
子组件@Prop变量的修改不会同步到父组件的状态变量上
允许装饰的变量类型string、number、boolean、enum 类型。
不支持 any,不允许使用 undefined 和 null。
必须指定类型。
在父组件中,传递给 @Prop 装饰的值不能为 undefined 或者 null
被装饰变量的初始值允许本地初始化

要理解 @Prop 变量值初始化和更新机制,有必要了解父组件和拥有 @Prop 变量的子组件初始渲染和更新流程。

1. 初始渲染:

⇒ 执行父组件的 build() 函数将创建子组件的新实例,将数据源传递给子组件;

⇒ 初始化子组件 @Prop 装饰的变量。

2. 更新:

⇒ 子组件 @Prop 更新时,更新仅停留在当前子组件,不会同步回父组件;

⇒ 当父组件的数据源更新时,子组件的 @Prop 装饰的变量将被来自父组件的数据源重置,所有 @Prop 装饰的本地的修改将被父组件的更新覆盖。

@Prop 装饰器使用场景

父组件 @State 到子组件 @Prop 简单数据类型同步

@Entry
@Component
struct Index {
  @State parentValue: number = 10;

  build() {
    Column() {
      Text(`父组件传递数据 ${this.parentValue}`).margin(20)
      // 父组件的数据源的修改会同步给子组件
      Button(`加一个 + 1`).onClick(() => {
        this.parentValue += 1;
      })
      // 父组件的修改会同步给子组件
      Button(`减一个 -1`).onClick(() => {
        this.parentValue -= 1;
      }).margin(20)

      CountDownComponent({ subValue: this.parentValue, costOfOneAttempt: 2 })
    }
    .width('100%')
  }
}

@Component
struct CountDownComponent {
  @Prop subValue: number;
  costOfOneAttempt: number = 1;

  build() {
    Column() {
      if (this.subValue > 0) {
        Text(`子组件获取到的数据: ${this.subValue}`).margin({ top: 50 })
      } else {
        Text('Over!').margin({ top: 50 })
      }
      // @Prop 装饰的变量不会同步给父组件
      Button(`子组件内部操作`).onClick(() => {
        this.subValue -= this.costOfOneAttempt;
      }).margin(20)
    }
  }
}

运行效果:

在这里插入图片描述

解读下代码:

  1. CountDownComponent 子组件首次创建时其 @Prop 装饰的 subValue 变量将从父组件 @State 装饰的 parentValue 变量初始化;
  2. 按“+1”或“-1”按钮时,父组件的 @State 装饰的 parentValue 值会变化,这将触发父组件重新渲染,在父组件重新渲染过程中会刷新使用 parentValue 状态变量的 UI 组件并单向同步更新 CountDownComponent 子组件中的 subValue 值;
  3. 更新 subValue 状态变量值也会触发 CountDownComponent 的重新渲染,在重新渲染过程中,评估使用 subValue 状态变量的 if 语句条件(this.subValue > 0),并执行 true 分支中的使用 subValue 状态变量的 UI 组件相关描述来更新 Text 组件的 UI 显示;
  4. 当按下子组件 CountDownComponent 的“子组件内部操作”按钮时,其 @Prop 变量 subValue 将被更改,但是 subValue 值的更改不会影响父组件的 parentValue 值;
  5. 父组件的 parentValue 值会变化时,父组件的修改将覆盖掉子组件 CountDownComponent 中 subValue 本地的修改。

父组件 @State 数组项到子组件 @Prop 简单数据类型同步

@Entry
@Component
struct Index {
  @State arr: number[] = [1,2,3];

  build() {
    Column() {
      Child({value: this.arr[0]})
      Child({value: this.arr[1]})
      Child({value: this.arr[2]})

      Divider().height(5)

      ForEach(this.arr,
        item => {
          Child({value: item})
        },
        item => item.toString()
      )

      Divider().height(5)

      Text('replace entire arr')
        .fontSize(40)
        .onClick(()=>{
          // 两个数组都包含项“3”。
          this.arr = this.arr[0] == 1 ? [3,4,5] : [1,2,3];
        })
    }
    .width('100%')
  }
}

@Component
struct Child {
  @Prop value: number;

  build() {
    Text(`${this.value}`)
      .fontSize(50)
      .onClick(()=>{this.value++})
  }
}

看下效果:

在这里插入图片描述

页面显示正常,接下来有意思的事情就发生了,我们看下实操效果:

在这里插入图片描述

方便你看到前后效果,我们对比下前后的结果图:

在这里插入图片描述

让我们来分析下这个数值变化:

  1. 在子组件 Child 中做的所有的修改都不会同步回父组件 Index 组件,所以即使 6 个组件显示都为 6,但在父组件 Index 中,this.arr 保存的值依旧是 [1,2,3]。
  2. 点击 replace entire arr,this.arr[0] == 1 成立,将 this.arr 赋值为 [3, 4, 5];
  3. 因为 this.arr[0] 已更改,Child({value: this.arr[0]}) 组件将 this.arr[0] 更新同步到实例 @Prop 装饰的变量。Child({value: this.arr[1]}) 和 Child({value: this.arr[2]}) 同理。
  4. this.arr 的更改触发 ForEach 更新,this.arr 更新的前后都有数值为 3 的数组项:[3, 4, 5] 和[1, 2, 3]。根据 diff 算法,数组项“3”将被保留,删除“1”和“2”的数组项,添加为“4”和“5”的数组项(关于 ForEach 的这个特性,不懂的可以查看 写给初学者的 HarmonyOS 教程 – 循环渲染(ForEach))。这就意味着,数组项“3”的组件不会重新生成,而是将其移动到第一位。所以“3”对应的组件不会更新,此时“3”对应的组件数值为“6”,ForEach最终的渲染结果是“6”,“4”,“5”。

从父组件中的 @State 类对象属性到 @Prop 简单类型的同步

class Book {
  public title: string;
  public pages: number;
  public readIt: boolean = false;

  constructor(title: string, pages: number) {
    this.title = title;
    this.pages = pages;
  }
}

@Component
struct ReaderComp {
  @Prop title: string;
  @Prop readIt: boolean;

  build() {
    Row() {
      Text(this.title)
      Text(`... ${this.readIt ? '已阅读' : '还没读'}`)
        .onClick(() => this.readIt = true)
    }
  }
}

@Entry
@Component
struct Index {
  @State book: Book = new Book('《 肖生克的救赎 》', 765);

  build() {
    Column() {
      ReaderComp({ title: this.book.title, readIt: this.book.readIt }).margin(20)
      ReaderComp({ title: this.book.title, readIt: this.book.readIt }).margin(20)
      ReaderComp({ title: this.book.title, readIt: this.book.readIt }).margin(20)
      ReaderComp({ title: this.book.title, readIt: this.book.readIt }).margin(20)
    }
    .width('100%')
  }
}

代码很简单,不用过多解释,直接看效果:

在这里插入图片描述

@Prop 本地初始化不和父组件同步

为了支持 @Component 装饰的组件复用场景,@Prop 支持本地初始化,这样可以让 @Prop 是否与父组件建立同步关系变得可选。当且仅当 @Prop 有本地初始化时,从父组件向子组件传递 @Prop 的数据源才是可选的。

下面的示例中,子组件包含两个 @Prop 变量:

  1. @Prop customCounter 没有本地初始化,所以需要父组件提供数据源去初始化 @Prop,并当父组件的数据源变化时,@Prop 也将被更新;
  2. @Prop customCounter2 有本地初始化,在这种情况下,@Prop 依旧允许但非强制父组件同步数据源给 @Prop。
@Component
struct MyComponent {
  @Prop customCounter: number;
  @Prop customCounter2: number = 5;

  build() {
    Column() {
      Row() {
        Text(`From Main: ${this.customCounter}`).width(90).height(40).fontColor('#FF0010')
      }

      Row() {
        Button('子组件本地修改 !').width(180).height(60).margin({ top: 10 })
          .onClick(() => {
            this.customCounter2++
          })
      }.height(100).width(180)

      Row() {
        Text(`Custom Local: ${this.customCounter2}`).width(90).height(40).fontColor('#FF0010')
      }
    }
  }
}

@Entry
@Component
struct Index {
  @State mainCounter: number = 10;

  build() {
    Column() {
      Row() {
        Column() {
          Button('修改数值').width(480).height(60).margin({ top: 10, bottom: 10 })
            .onClick(() => {
              this.mainCounter++
            })
        }
      }

      Row() {
        // customCounter 必须从父组件初始化,因为 MyComponent 的 customCounter 成员变量缺少本地初始化;此处,customCounter2 可以不做初始化。
        MyComponent({ customCounter: this.mainCounter })
        // customCounter2 也可以从父组件初始化,父组件初始化的值会覆盖子组件 customCounter2 的本地初始化的值
        MyComponent({ customCounter: this.mainCounter, customCounter2: this.mainCounter })
      }
    }
  }
}

效果:

在这里插入图片描述

@Link 装饰器使用规则

@Link变量装饰器说明
装饰器参数
同步类型双向同步。
父组件中 @State/@StorageLink/@Link 和子组件 @Link 可以建立双向数据同步,反之亦然。
允许装饰的变量类型Object、class、string、number、boolean、enum 类型,以及这些类型的数组。
类型必须被指定,且和双向绑定状态变量的类型相同。
不支持 any,不支持简单类型和复杂类型的联合类型,不允许使用 undefined 和 null。
被装饰变量的初始值无,禁止本地初始化。

为了了解 @Link 变量初始化和更新机制,有必要先了解父组件和拥有 @Link 变量的子组件的关系,初始渲染和双向更新的流程(以父组件为 @State 为例)。

1. 初始渲染:

执行父组件的 build() 函数后将创建子组件的新实例。初始化过程如下:

⇒ 必须指定父组件中的 @State 变量,用于初始化子组件的 @Link 变量。子组件的 @Link 变量值与其父组件的数据源变量保持同步(双向数据同步)。

⇒ 父组件的 @State 状态变量包装类通过构造函数传给子组件,子组件的 @Link 包装类拿到父组件的 @State 的状态变量后,将当前 @Link 包装类 this 指针注册给父组件的 @State 变量。

2. @Link 的数据源更新:

即父组件中状态变量更新,引起相关子组件的 @Link 的更新,处理步骤:

⇒ 通过初始渲染的步骤可知,子组件 @Link 包装类把当前 this 指针注册给父组件。父组件 @State 变量变更后,会遍历更新所有依赖它的系统组件(elementid)和状态变量(比如 @Link 包装类)。

⇒ 通知 @Link 包装类更新后,子组件中所有依赖 @Link 状态变量的系统组件(elementId)都会被通知更新。以此实现父组件对子组件的状态数据同步。

3. @Link的更新:

当子组件中 @Link 更新后,处理步骤如下(以父组件为 @State 为例):

⇒ @Link 更新后,调用父组件的 @State 包装类的 set 方法,将更新后的数值同步回父组件。

⇒ 子组件 @Link 和父组件 @State 分别遍历依赖的系统组件,进行对应的 UI 的更新。以此实现子组件 @Link 同步回父组件 @State。

@Link 装饰器使用场景

简单类型和类对象类型的 @Link

以下示例中,点击父组件 ShufflingContainer 中的 “父组件: 设置红色 Button” 和 “父组件: 设置蓝色 Button”,可以从父组件将变化同步给子组件,子组件 GreenButton 和 RedButton 中 @Link 装饰变量的变化也会同步给其父组件。

class BlueButtonState {
  width: number = 0;
  constructor(width: number) {
    this.width = width;
  }
}

@Component
struct BlueButton {
  @Link blueButtonState: BlueButtonState;
  build() {
    Button('Blue Button')
      .width(this.blueButtonState.width)
      .height(120.0)
      .backgroundColor('#085DFF')
      .onClick(() => {
        if (this.blueButtonState.width < 400) {
          // 更新 class 的属性,变化可以被观察到同步回父组件
          this.blueButtonState.width += 50;
        } else {
          // 更新 class 的属性,变化可以被观察到同步回父组件
          this.blueButtonState = new BlueButtonState(200);
        }
      })
  }
}
@Component
struct RedButton {
  @Link redButtonState: number;
  build() {
    Button('Red Button')
      .width(this.redButtonState)
      .height(150.0)
      .backgroundColor('#ff0000')
      .onClick(() => {
        // 子组件的简单类型可以同步回父组件
        this.redButtonState += 20.0;
      })
  }
}
@Entry
@Component
struct ShufflingContainer {
  @State blueButtonState: BlueButtonState = new BlueButtonState(200);
  @State redButtonProp: number = 100;
  build() {
    Column() {
      // class 类型从父组件 @State 向子组件 @Link 数据同步
      Button('父组件: 设置绿色 Button')
        .onClick(() => {
          this.blueButtonState.width = (this.blueButtonState.width < 400) ? this.blueButtonState.width + 100 : 100;
        }).margin(20)
      // class 类型初始化 @Link
      BlueButton({ blueButtonState: $blueButtonState })
      Divider().height(20)
      // 简单类型从父组件 @State 向子组件 @Link 数据同步
      Button('父组件: 设置红色 Button')
        .onClick(() => {
          this.redButtonProp = (this.redButtonProp < 400) ? this.redButtonProp + 100 : 100;
        }).margin(20)
      // 简单类型初始化 @Link
      RedButton({ redButtonState: $redButtonProp })
    }.width('100%').justifyContent(FlexAlign.Center)
  }
}

运行效果:

在这里插入图片描述

数组类型的@Link

@Component
struct Child {
  @Link items: number[];

  build() {
    Column() {
      Button(`Button1: push`).onClick(() => {
        this.items.push(this.items.length + 1);
      }).margin(20)
      Button(`Button2: replace whole item`).onClick(() => {
        this.items = [100, 200, 300];
      })
    }
  }
}

@Entry
@Component
struct Parent {
  @State arr: number[] = [1, 2, 3];

  build() {
    Column() {
      Child({ items: $arr })
      Divider().height(20)
      ForEach(this.arr,
        item => {
          Text(`${item}`)
        },
        item => item.toString()
      )
    }.width('100%')
  }
}

运行效果:

在这里插入图片描述

ArkUI 框架可以观察到数组元素的添加,删除和替换。在该示例中 @State 和 @Link 的类型是相同的 number[],不允许将@Link 定义成 number 类型(@Link item : number),并在父组件中用 @State 数组中每个数据项创建子组件。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1285295.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

配置texstudio编译器

目录 1 .编辑器介绍2. 软件下载3. 测试编辑器 1 .编辑器介绍 latex可用的编辑器有配套的texstudio软件&#xff0c;也可以通过配置VScode来作为编辑器&#xff0c;但是个人感觉vscode配置较为复杂&#xff08;失败了&#xff09;&#xff0c;所以本篇介绍texstudio的配置&…

Java Socket编程之基于TCP协议通信

1.说明 Socket&#xff08;套接字&#xff09;是计算机网络编程中用于实现网络通信的一种编程接口或抽象概念。 它提供了一种标准的接口&#xff0c;使应用程序能够通过网络与其他计算机进行通信。 Socket可以看作是应用程序与网络之间的一个通信端点&#xff0c;类似于电话中…

qt 5.15.2 主窗体事件及绘制功能

qt 5.15.2 主窗体事件及绘制功能 显示主窗体效果图如下所示&#xff1a; main.cpp #include "mainwindow.h"#include <QApplication>int main(int argc, char *argv[]) {QApplication a(argc, argv);MainWindow w;w.setFixedWidth(600);w.setFixedHeight(6…

什么是 AWS IAM?如何使用 IAM 数据库身份验证连接到 Amazon RDS(下)

在《什么是 AWS IAM&#xff1f;如何使用 IAM 数据库身份验证连接到 Amazon RDS&#xff08;上&#xff09;》中我们已经阅读了有关LAM的部分内容&#xff0c;这篇在文章中我们将继续为您展开↓ dbForge Studio for MySQL是一款专业的数据库管理、开发软件&#xff0c;它能够使…

探索C++14新特性:更强大、更高效的编程

探索C14新特性&#xff1a;更强大、更高效的编程 C14并没有太大的改动&#xff0c;就连官方说明中也指出&#xff0c;C14相对于C11来说是一个比较小的改动&#xff0c;但是在很大程度上完善了C11&#xff0c;所以可以说C14就是在C11标准上的查漏补缺。 C14在2014年8月18日正式…

Qt篇——QChartView实现鼠标滚轮缩放、鼠标拖拽平移、鼠标双击重置缩放平移、曲线点击显示坐标

话不多说。 第一步&#xff1a;自定义QChartView&#xff0c;直接搬 FirtCurveChartView.h #ifndef FITCURVECHARTVIEW_H #define FITCURVECHARTVIEW_H #include <QtCharts>class FitCurveChartView : public QChartView {Q_OBJECTpublic:FitCurveChartView(QWidget *…

apk反编译修改教程系列---简单去除apk开屏广告【五】

往期教程&#xff1a; apk反编译修改教程系列-----修改apk应用名称 任意修改名称 签名【一】 apk反编译修改教程系列-----任意修改apk版本号 版本名 防止自动更新【二】 apk反编译修改教程系列-----修改apk中的图片 任意更换apk桌面图片【三】 apk反编译修改教程系列---简单…

算法学习—排序

排序算法 一、选择排序 1.算法简介 选择排序是一个简单直观的排序方法&#xff0c;它的工作原理很简单&#xff0c;首先从未排序序列中找到最大的元素&#xff0c;放到已排序序列的末尾&#xff0c;重复上述步骤&#xff0c;直到所有元素排序完毕。 2.算法描述 1&#xff…

Linux中项目部署步骤

安装jdk&#xff0c;tomcat 安装步骤 1&#xff0c;将压缩包&#xff0c;拷贝到虚拟机中。 通过工具&#xff0c;将文件直接拖到虚拟机的/home下 2&#xff0c;回到虚拟机中&#xff0c;查看/home下&#xff0c;有两个压缩文件 3&#xff0c;给压缩文件做解压缩操作 tar -z…

分享70个节日PPT,总有一款适合您

分享70个节日PPT&#xff0c;总有一款适合您 70个节日PPT下载链接&#xff1a;https://pan.baidu.com/s/1IRIKuFoGjQJ14OVkeW_mDQ?pwd6666 提取码&#xff1a;6666 Python采集代码下载链接&#xff1a;采集代码.zip - 蓝奏云 学习知识费力气&#xff0c;收集整理更不易…

Nuxt3 使用 pinia 基础

官方文档 一、安装 pnpm add pinia/nuxt二、配置 添加到 nuxt.config.js 中的 modules &#xff08;Nuxt 3&#xff09;或 buildModules &#xff08;Nuxt 2&#xff09;&#xff1a; // Nuxt 2 export default {buildModules: [[pinia/nuxt, { disableVuex: true }]], } /…

MySQL-含json字段表和与不含json字段表查询性能对比

含json字段表和与不含json字段表查询性能对比 说明: EP_USER_PICTURE_INFO_2:不含json字段表 20200729json_test:含有json字段表 其中20200729json_test 标准ID、MANAGER_NO、PHONE_NO 为非json字段 data为json字段 2个表中MANAGER_NO、PHONE_NO都创建了各自的索引 测试…

拼多多电商平台API接口,获取拼多多实时准确数据,获取产品销量、价格,sku图片及sku库存数据演示

拼多多商品详情API接口的作用是让开发者可以获取拼多多平台上特定商品的详细信息&#xff0c;包括商品的标题、价格、图片、规格、参数以及店铺信息等。通过这个接口&#xff0c;开发者可以轻松地获取商品的原始数据&#xff0c;便于进行数据分析、价格比较、爬取等操作。这为电…

python和php语言编写大型爬虫那个更适用 ?

以我多年从事爬虫行业的经验来说&#xff0c;其实python和php两种语言都可以用于编写大型爬虫项目&#xff0c;但是因为Python语言简洁方便&#xff0c;第三方库相比有很多&#xff0c;数据处理能力也很强&#xff0c;所以受到大多数程序员的追捧。 Python和PHP都可以用于编写…

32位旧内核2038溢出time记录

项目中有使用arm32的机器 现在内核动不了 有个使用时间范围显示是2023-2123 int在32bit下的 2038危机诞生了。 下面在svn找到代码 优化了一下 供大家学习哈&#xff0c;废话不多说直接上家伙&#xff1a; 需要的函数自己抄 #pragma once #include <stdio.h> #include …

Java 并发编程面试题——Java 线程间通信方式

目录 1.✨Java 线程间有哪些通信方式&#xff1f;1.1.volatile 和 synchronized 关键字1.2.等待/通知机制1.2.1.概述1.2.2.经典范式 1.3.管道输入/输出流1.4.信号量 2.Thread.join() 有什么作用&#xff1f;它的使用场景是什么&#xff1f;3.Java 中需要主线程等待子线程执行完…

家用打印机品牌多,种类杂,那么如何挑选最适合的家用打印机

在购买最好的家用打印机时&#xff0c;你可能会寻找足够多功能的打印机来满足每个人的需求。你的家人可能需要复印文件签字&#xff0c;扫描精致的旧照片&#xff0c;或者在接到通知后立即打印长篇文章或报告。良好的扫描功能确保你可以快速高效地将工作数字化&#xff0c;而每…

工程化使用React

安装 首先全局安装 npm install create-react-app -g创建项目 create-react-app proName最基本的一个react工程化创建完成 项目目录

CRM:如何通过客户数据分析获得业务洞察?

客户数据分析&#xff0c;也称客户分析&#xff0c;是收集、组织和分析客户数据&#xff0c;以深入了解客户行为的过程。企业将利用这些数据来制定与营销、产品开发、销售等相关的业务决策。 通过客户分析&#xff0c;你可以做出简单的业务决策&#xff0c;比如找出投资回报率…