This article aims to deeply explore the technical details of the Huawei HarmonyOS Next system (up to API 12 as of now), and is summarized based on actual development practices.
It mainly serves as a vehicle for technical sharing and communication. Mistakes and omissions are inevitable. Colleagues are welcome to put forward valuable opinions and questions so that we can make progress together.
This article is original content, and any form of reprint must indicate the source and the original author.Introduction
In the ArkWeb framework, page loading and browsing history navigation are functions that developers often need to use. By mastering these functions, you can easily load Web pages, manage browsing history, and enhance the user experience. This article will introduce the basic operations of page loading and browsing history navigation in the ArkWeb framework.
Page Loading
Loading Web Pages
You can load web pages in two ways:
- Using the src Attribute: Specify the URL of the web page in the src attribute of the Web component, for example:
Web({ src: "https://www.example.com" });
- Using the loadUrl Method: After creating the Web component, use the loadUrl method to load the web page, for example:
Web({ src: $rawfile("local.html") })
.onControllerAttached(() => {
this.controller.loadUrl("https://www.example.com");
});
You can use the loadUrl method to dynamically change the loaded page after creating the Web component.
Loading Local Pages
You can load local pages in two ways:
- Using $rawfile: Use the $rawfile function in the src attribute of the Web component to load local pages, for example:
Web({ src: $rawfile("local.html") });
- Using the loadUrl Method: After creating the Web component, use the loadUrl method to load local pages, for example:
Web({ src: $rawfile("local.html") })
.onControllerAttached(() => {
this.controller.loadUrl($rawfile("another_local.html"));
});
You can use the loadUrl method to dynamically change the loaded page after creating the Web component.
Loading HTML Text Data
You can load HTML text data using the loadData method, for example:
Web({ src: $rawfile("local.html") })
.onControllerAttached(() => {
this.controller.loadData("<html><body>Hello, World!</body></html>", "text/html", "UTF-8");
});
You need to specify the data type, encoding format, and content.
Loading Modes
The ArkWeb framework supports two loading modes:
- Synchronous Rendering Mode: The default mode, where Web rendering is performed together with system components.
- Asynchronous Rendering Mode: The Web component is rendered as an independent node, with higher performance but limited by the maximum size. You can set the loading mode using the renderMode property, for example:
Web({ src: "https://www.example.com", renderMode: RenderMode.ASYNC_RENDER });
Loading Progress Monitoring
You can monitor the page loading progress using the onProgressChange interface, for example:
Web({ src: "https://www.example.com" })
.onProgressChange((event) => {
console.log("Loading progress: " + event.newProgress);
});
Browsing History Navigation
Forward and Backward
You can use the forward and backward methods to perform page forward and backward operations, for example:
Web({ src: "https://www.example.com" })
.onControllerAttached(() => {
this.controller.forward(); // Move forward
this.controller.backward(); // Move backward
});
You can use the accessForward and accessBackward methods to check whether there is a forward or backward browsing history, for example:
javascript
Web({ src: "www.example.com" })
.onControllerAttached(() => {
if (this.controller.accessForward()) {
this.controller.forward(); // If there is a forward history, move forward
}
if (本题可通过设未知数,根据路程、速度、时间的关系列方程求解。
1. **分析题目:**
已知客车速度为\(55\)千米/小时,货车速度为\(45\)千米/小时,两车相向而行,经过一段时间后相距\(30\)千米,此时两车行驶的总路程为\(480 - 30 = 450\)千米(因为是相向而行还未相遇相距\(30\)千米),要求两车行驶的时间,可根据路程和速度的关系来求解。
2. **设未知数:**
设两车行驶的时间为\(t\)小时。
3. **根据路程、速度、时间的关系列方程:**
客车行驶的路程为\(55t\)千米,货车行驶的路程为\(45t\)千米,两车行驶的总路程为\(450\)千米,可列方程:
\(55t + 45t = 450\)
4. **解方程:**
\[
\begin{align*}
55t + 45t &= 450\\
100t &= 450\\
t &= 450\div100\\
t &= 4.5
\end{align*}
\]
所以,两车行驶了\(4.5\)小时。
如果两车相遇后继续行驶,相距\(30\)千米,此时两车行驶的总路程为\(480 + 30 = 510\)千米,同样设两车行驶的时间为\(t\)小时,可列方程:
\(55t + 45t = 510\)
解方程:
\[
\begin{align*}
55t + 45t &= 510\\
100t &= 510\\
t &= 510\div100\\
t &= 5.1
\end{align*}
\]
所以,这种情况下两车行驶了\(5.1\)小时。
综上,两车行驶时间为\(4.5\)小时(未相遇相距\(30\)千米时)或\(5.1\)小时(相遇后相距\(30\)千米时)。
Top comments (0)