Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vue.component( 'parent-component', {
- template: '#parent-component',
- data: function() {
- return {
- testObject: {
- val: 'Test Value'
- }
- }
- },
- methods: {
- // Added this method to listen for input event changes
- onChange(newValue) {
- this.testObject.val = newValue;
- // Or if you favor immutability
- // this.testObject = {
- // ...this.testObject,
- // val: newValue
- // };
- }
- }
- });
- <script type="text/x-template" id="parent-component">
- <div>
- <child-component :test_object="testObject"
- @inputChange="onChange"></child-component>
- <p>This is in the parent component</p>
- <p><code>testObject.val = {{testObject.val}}</code></p>
- </div>
- </script>
- <!-- Instead of v-model, you can use :value and @input binding. -->
- <script type="text/x-template" id="child-component">
- <div>
- <label for="html_input">HTML Input</label>
- <input type="text" name="html_input"
- :value="test_object.val"
- @input="$emit('inputChange', $event.target.value)" />
- </div>
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement