Vue component modifies the data method of the root instance (with code)

不言
Release: 2019-04-02 10:06:44
forward
2303 people have browsed it

The content of this article is about the data method of modifying the root instance of the Vue component (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Idea:
1 Listen to the event inside the component and emit the event
2 Listen to the emit event on the component
3 When the event occurs, execute the corresponding function to modify the root instance Data

Implementation:
1 Listen to the input event in the input box inside the component and bind the input event
triggerInput function
2 When content is entered into the input box, it is triggered triggerInput function
The triggerInput function emits an edit event and the value of the input box to the outside
3 Listen to this edit event on the component and bind the triggerEdit function to the edit event
4 At this time, the triggerEdit function, triggerEdit function will be triggered You can modify the data on the root instance

Note:
1 The first parameter of the triggerEdit function is the key of the root instance data you want to modify
2 The second parameter $event is Routine, only with this parameter can you get the value of the input box emitted inside the component in the triggerEdit function
3 You can log out the events that occur inside the component in the triggerEdit function

nbsp;html>    
根实例的 data message:{{message}}
根实例的 data name:{{name}}
message: name:
Copy after login

Vue component modifies the data method of the root instance (with code)

【Related recommendations:

JavaScript video tutorial

The above is the detailed content of Vue component modifies the data method of the root instance (with code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!