0
0
Vueframework~10 mins

Render function syntax in Vue - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a simple render function that returns a <div> element.

Vue
export default {
  render() {
    return [1]('div', 'Hello World')
  }
}
Drag options to blanks, or click blank then click option'
AcreateElement
Brender
Ch
Ddiv
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'render' instead of the helper function.
Using 'div' as a function instead of a string tag name.
Using 'createElement' without importing or aliasing it.
2fill in blank
medium

Complete the render function to create a <button> element with text 'Click me'.

Vue
export default {
  render() {
    return h([1], 'Click me')
  }
}
Drag options to blanks, or click blank then click option'
A'div'
B'button'
C'span'
D'input'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a tag name that does not match the desired element.
Forgetting the quotes around the tag name.
3fill in blank
hard

Fix the error in the render function by completing the code to create a <p> element with dynamic text.

Vue
export default {
  data() {
    return { message: 'Hello Vue' }
  },
  render() {
    return h('p', [1])
  }
}
Drag options to blanks, or click blank then click option'
Athis.message
Bmessage
C'message'
Dthis.data.message
Attempts:
3 left
💡 Hint
Common Mistakes
Using just 'message' without 'this'.
Using a string 'message' instead of the variable.
Trying to access data with 'this.data.message' which is incorrect.
4fill in blank
hard

Fill both blanks to create a <ul> with two <li> children using the render function.

Vue
export default {
  render() {
    return h('ul', null, [
      h([1], 'Item 1'),
      h([2], 'Item 2')
    ])
  }
}
Drag options to blanks, or click blank then click option'
A'li'
B'ul'
C'div'
D'span'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ul' or 'div' instead of 'li' for list items.
Mixing different tags for the two items.
5fill in blank
hard

Fill all three blanks to create a render function that returns a <button> with a click event and label.

Vue
export default {
  methods: {
    handleClick() {
      alert('Clicked!')
    }
  },
  render() {
    return h('button', { [1]: this.[2] }, [3])
  }
}
Drag options to blanks, or click blank then click option'
AonClick
BhandleClick
C'Click me!'
Donclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'onClick' instead of 'onclick' for event name.
Using the wrong method name.
Forgetting quotes around the button label.