1e41f4b71Sopenharmony_ci# FAQs<a name="EN-US_TOPIC_0000001055049072"></a>
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Visual Application FAQs<a name="section147421736145813"></a>
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci### Is there a global variable that can be accessed by all pages?<a name="section294382614018"></a>
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciThere is no such a global variable.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci### How do I obtain DOM elements?<a name="section1423713435019"></a>
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ciYou can obtain DOM elements via the  **ref**  attribute. You can use methods of the obtained elements but cannot change their attributes. The sample code is as follows:
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci```
14e41f4b71Sopenharmony_ci<!--index.hml-->
15e41f4b71Sopenharmony_ci<div class="container">
16e41f4b71Sopenharmony_ci   <!-- Set the ref attribute of the component to animator -->.
17e41f4b71Sopenharmony_ci   <image-animator class="image-player" ref="animator" images="{{images}}" duration="1s" onclick="handleClick"></image-animator>
18e41f4b71Sopenharmony_ci</div>
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci/* index.js */
21e41f4b71Sopenharmony_ciexport default {
22e41f4b71Sopenharmony_ci    data: {
23e41f4b71Sopenharmony_ci        images:[
24e41f4b71Sopenharmony_ci            {src:"common/frame1.png"},
25e41f4b71Sopenharmony_ci            {src:"common/frame2.png"},
26e41f4b71Sopenharmony_ci            {src:"common/frame3.png"}
27e41f4b71Sopenharmony_ci        ]
28e41f4b71Sopenharmony_ci    },
29e41f4b71Sopenharmony_ci    handleClick(){
30e41f4b71Sopenharmony_ci        // Obtain the component through the $refs attribute. (The ref attribute of the component has been set to animator in the HML file.)
31e41f4b71Sopenharmony_ci        const animator = this.$refs.animator;
32e41f4b71Sopenharmony_ci        const state = animator.getState();
33e41f4b71Sopenharmony_ci        if(state == "paused"){
34e41f4b71Sopenharmony_ci            animator.resume();
35e41f4b71Sopenharmony_ci        }else if(state == "stopped"){
36e41f4b71Sopenharmony_ci            animator.start();
37e41f4b71Sopenharmony_ci        }else{
38e41f4b71Sopenharmony_ci            animator.pause();
39e41f4b71Sopenharmony_ci        }
40e41f4b71Sopenharmony_ci    }
41e41f4b71Sopenharmony_ci}
42e41f4b71Sopenharmony_ci```
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci### How do I pass values between pages?<a name="section119822143117"></a>
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ciYou can pass values through  **params**  of the  **router.replace**  method. The sample code is as follows:
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ciSet  **params**  to the values to be passed on a page.
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci```
51e41f4b71Sopenharmony_cirouter.replace({
52e41f4b71Sopenharmony_ci     uri:'pages/detail/detail',  // URI of the page to switch to.
53e41f4b71Sopenharmony_ci    params:{transferData:this.data} // Data to be transferred. You need to define the data amount and name.
54e41f4b71Sopenharmony_ci});
55e41f4b71Sopenharmony_ci```
56e41f4b71Sopenharmony_ci
57e41f4b71Sopenharmony_ciReceive the passed values on another page.
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci```
60e41f4b71Sopenharmony_cionInit(){
61e41f4b71Sopenharmony_ci    const data = this.transferData; // Receive the transferred data by the onInit function.
62e41f4b71Sopenharmony_ci}  
63e41f4b71Sopenharmony_ci```
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci### How do I scroll a list to an item?<a name="section188663819111"></a>
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ciCall the  **scrollTo**  method of the list. The input parameter of this method is the index of the target item. You can specify an item index, or obtain the index through the  **scrollend**  event.
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci### Does the  **<text\>**  component support multiple lines?<a name="section205741157418"></a>
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ciYes. You can use the Enter key to start a new line. Alternatively, the component automatically starts a new line based on the content, without the need to set the height attribute of the text.
72e41f4b71Sopenharmony_ci
73e41f4b71Sopenharmony_ci### Why is a component not displayed?<a name="section1345810151025"></a>
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci**Description**
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ciThe component added to the  **.hml**  file cannot be displayed.
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci**Possible Causes**
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci-   The width and height of the component may not be set.
82e41f4b71Sopenharmony_ci-   The style setting may be incorrect.
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**Solution**
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci\(1\) Check whether the width and height values are set explicitly.
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci\(2\) Check whether the style of the component is set correctly.
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci### How do I implement scrolling on a page?<a name="section1724052813218"></a>
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ciThere are three ways to implement page scrolling:  **scroll**,  **<list\>**, or  **<swiper\>**. For a root component with  **scroll**  set, the scrolling effect is automatically implemented when the component size exceeds the screen size. For details, see the development specifications.
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci### Why do not the  **left**  and  **top**  attributes take effect?<a name="section34659571520"></a>
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci**left**  and  **top**  attributes must work with the  **<stack\>**  component in addition to the root component.
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci### Why does not dynamic binding take effect?<a name="section1758881511313"></a>
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ciThe object or its attributes are not defined before dynamic binding.
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci### How do I implement relative and absolute positioning?<a name="section1378730235"></a>
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ciYou can use the  **<div\>**  and  **<stack\>**  \(with  **top**  and  **left**  attributes\) components.
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci### How do I display or hide a component?<a name="section1243424718312"></a>
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ciYou can use  **display**,  **show**, or  **if**. When an  **if**  clause evaluates to  **false**, the corresponding component will be removed from the VDOM. When  **show**  is set to  **false**, the component will be invisible during rendering, but will not be removed from the VDOM.
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci### What are the precautions for using the  **margin**  attribute?<a name="section7923357414"></a>
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ciThe  **margin**  attribute cannot be set for child components of the  **<stack\>**  component.
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci### What are the precautions for event subscription?<a name="section91641925548"></a>
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ciOnly one page exists when the application is running. Therefore, the  **router.replace**  function destroys the previous page and then creates a new one. For pages involving event subscription, an event should be subscribed every time a page is created, and unsubscribed before page switching.
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci### What are the precautions for using dynamic binding?<a name="section1292412431744"></a>
119e41f4b71Sopenharmony_ci
120e41f4b71Sopenharmony_ciDo not use too many dynamic bindings because they consume too much memory.
121e41f4b71Sopenharmony_ci
122e41f4b71Sopenharmony_ci### How does the  **loop**  attribute take effect for  **<swiper\>**?<a name="section1136434952"></a>
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ciIf the total length of the child components, except for the first and last ones, is greater than the length of  **<swiper\>**, the  **loop**  attribute takes effect.
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci### What are the precautions for using an array?<a name="section1979819133510"></a>
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ciDo not include too many elements in an array. Avoid frequent operations on a large array.
129e41f4b71Sopenharmony_ci
130