0
0
Vueframework~10 mins

Why render functions exist in Vue - Test Your Understanding

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

Complete the code to create a simple Vue render function that returns a <div> with text.

Vue
export default {
  render() {
    return [1]('div', 'Hello Vue!')
  }
}
Drag options to blanks, or click blank then click option'
Ah
BcreateElement
Crender
Dtemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'template' inside render function which is not valid.
Using 'render' instead of the element creator function.
2fill in blank
medium

Complete the code to pass props to a child component using a render function.

Vue
export default {
  render() {
    return this.$createElement('ChildComponent', { props: { message: [1] } })
  }
}
Drag options to blanks, or click blank then click option'
Athis.message
Bmessage
C'Hello'
Dprops.message
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'message' without 'this' which is undefined in this context.
Using 'props.message' which is not directly accessible here.
3fill in blank
hard

Fix the error in the render function to correctly render a list of items.

Vue
export default {
  data() {
    return { items: ['a', 'b', 'c'] }
  },
  render() {
    return this.items.map(item => [1]('li', item))
  }
}
Drag options to blanks, or click blank then click option'
Arender
BcreateElement
Ch
Dtemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'render' or 'template' inside the map which causes errors.
Not using any function to create elements.
4fill in blank
hard

Fill both blanks to create a render function that conditionally renders a <p> or <span> element.

Vue
export default {
  data() {
    return { isParagraph: true }
  },
  render() {
    return this.isParagraph ? [1]('p', 'Paragraph') : [2]('span', 'Span')
  }
}
Drag options to blanks, or click blank then click option'
Ah
BcreateElement
Crender
Dtemplate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'render' or 'template' instead of element creator functions.
Using different functions that don't create elements.
5fill in blank
hard

Fill all three blanks to create a render function that returns a <ul> with <li> children from an array.

Vue
export default {
  data() {
    return { fruits: ['apple', 'banana', 'cherry'] }
  },
  render() {
    return [1]('ul', this.fruits.map(fruit => [2]('li', [3])))
  }
}
Drag options to blanks, or click blank then click option'
Ah
BcreateElement
Cfruit
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong function names for creating elements.
Not passing the fruit variable as the text content.