Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. Vue.component( 'parent-component', {
  2. template: '#parent-component',
  3. data: function() {
  4. return {
  5. testObject: {
  6. val: 'Test Value'
  7. }
  8. }
  9. },
  10.  
  11. methods: {
  12. // Added this method to listen for input event changes
  13. onChange(newValue) {
  14. this.testObject.val = newValue;
  15.  
  16. // Or if you favor immutability
  17. // this.testObject = {
  18. // ...this.testObject,
  19. // val: newValue
  20. // };
  21. }
  22. }
  23. });
  24.  
  25. <script type="text/x-template" id="parent-component">
  26. <div>
  27. <child-component :test_object="testObject"
  28. @inputChange="onChange"></child-component>
  29.  
  30. <p>This is in the parent component</p>
  31. <p><code>testObject.val = {{testObject.val}}</code></p>
  32.  
  33. </div>
  34. </script>
  35.  
  36. <!-- Instead of v-model, you can use :value and @input binding. -->
  37. <script type="text/x-template" id="child-component">
  38. <div>
  39. <label for="html_input">HTML Input</label>
  40. <input type="text" name="html_input"
  41. :value="test_object.val"
  42. @input="$emit('inputChange', $event.target.value)" />
  43. </div>
  44. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement