-``` js
+```js
app.component('TodoItem', {
props: {
todo: {
@@ -1594,7 +1594,7 @@ app.component('TodoItem', {
})
```
-``` js
+```js
app.component('TodoItem', {
props: {
todo: {
@@ -1628,7 +1628,7 @@ Vuex is the [official flux-like implementation](/guide/state-management.html#off
Bad
-``` js
+```js
// main.js
import { createApp } from 'vue'
import mitt from 'mitt'
@@ -1657,7 +1657,7 @@ const app = createApp({
Good
-``` js
+```js
// store/modules/todos.js
export default {
state: {
@@ -1678,7 +1678,7 @@ export default {
}
```
-``` html
+```html
From da874b21fab5d00cd6edb876d69a841c0052ee69 Mon Sep 17 00:00:00 2001
From: skirtle <65301168+skirtles-code@users.noreply.github.com>
Date: Tue, 27 Apr 2021 15:05:03 +0100
Subject: [PATCH 2/3] docs: return values for render functions (#1006)
---
src/guide/render-function.md | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/guide/render-function.md b/src/guide/render-function.md
index 80360f6dc4..37a44c73bc 100644
--- a/src/guide/render-function.md
+++ b/src/guide/render-function.md
@@ -567,6 +567,33 @@ render () {
}
```
+## Return Values for Render Functions
+
+In all of the examples we've seen so far, the `render` function has returned a single root VNode. However, there are alternatives.
+
+Returning a string will create a text VNode, without any wrapping element:
+
+```js
+render() {
+ return 'Hello world!'
+}
+```
+
+We can also return an array of children, without wrapping them in a root node. This creates a fragment:
+
+```js
+// Equivalent to a template of `Hello
world!`
+render() {
+ return [
+ 'Hello',
+ h('br'),
+ 'world!'
+ ]
+}
+```
+
+If a component needs to render nothing, perhaps because data is still loading, it can just return `null`. This will be rendered as a comment node in the DOM.
+
## JSX
If we're writing a lot of `render` functions, it might feel painful to write something like this:
From 5753b78caa80309065554b2c2583bcdce03bc325 Mon Sep 17 00:00:00 2001
From: skirtle <65301168+skirtles-code@users.noreply.github.com>
Date: Tue, 27 Apr 2021 15:54:34 +0100
Subject: [PATCH 3/3] chore: switch javascript code blocks to js (#1020)
---
src/guide/migration/custom-directives.md | 4 ++--
src/guide/migration/filters.md | 2 +-
src/guide/migration/listeners-removed.md | 4 ++--
src/guide/render-function.md | 2 +-
src/guide/single-file-component.md | 4 ++--
5 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/guide/migration/custom-directives.md b/src/guide/migration/custom-directives.md
index 985267b0e3..e6a2b32182 100644
--- a/src/guide/migration/custom-directives.md
+++ b/src/guide/migration/custom-directives.md
@@ -85,7 +85,7 @@ It's generally recommended to keep directives independent of the component insta
In Vue 2, the component instance had to be accessed through the `vnode` argument:
-```javascript
+```js
bind(el, binding, vnode) {
const vm = vnode.context
}
@@ -93,7 +93,7 @@ bind(el, binding, vnode) {
In Vue 3, the instance is now part of the `binding`:
-```javascript
+```js
mounted(el, binding, vnode) {
const vm = binding.instance
}
diff --git a/src/guide/migration/filters.md b/src/guide/migration/filters.md
index f622ade9c2..cc58cbb572 100644
--- a/src/guide/migration/filters.md
+++ b/src/guide/migration/filters.md
@@ -79,7 +79,7 @@ If you are using filters that were globally registered and then used throughout
Instead, you can make your global filters available to all components through [globalProperties](../../api/application-config.html#globalproperties):
-```javascript
+```js
// main.js
const app = createApp(App)
diff --git a/src/guide/migration/listeners-removed.md b/src/guide/migration/listeners-removed.md
index 5a84f3592a..f6c650c5b0 100644
--- a/src/guide/migration/listeners-removed.md
+++ b/src/guide/migration/listeners-removed.md
@@ -10,7 +10,7 @@ badges:
The `$listeners` object has been removed in Vue 3. Event listeners are now part of `$attrs`:
-```javascript
+```js
{
text: 'this is an attribute',
onClose: () => console.log('close Event triggered')
@@ -54,7 +54,7 @@ export default {
If this component received an `id` attribute and a `v-on:close` listener, the `$attrs` object will now look like this:
-```javascript
+```js
{
id: 'my-input',
onClose: () => console.log('close Event triggered')
diff --git a/src/guide/render-function.md b/src/guide/render-function.md
index 37a44c73bc..fda002f2e2 100644
--- a/src/guide/render-function.md
+++ b/src/guide/render-function.md
@@ -354,7 +354,7 @@ For the `.passive`, `.capture`, and `.once` event modifiers, they can be concate
For example:
-```javascript
+```js
render() {
return h('input', {
onClickCapture: this.doThisInCapturingMode,
diff --git a/src/guide/single-file-component.md b/src/guide/single-file-component.md
index 7760d56097..a92b709130 100644
--- a/src/guide/single-file-component.md
+++ b/src/guide/single-file-component.md
@@ -90,7 +90,7 @@ touch rollup.config.js
Once the file is created we will need to open it with our editor of choice and add the following code.
-```javascript
+```js
// import our third party plugins
import commonjs from 'rollup-plugin-commonjs'
import VuePlugin from 'rollup-plugin-vue'
@@ -144,7 +144,7 @@ Here we are specifying:
To also build `umd` and `cjs` modules we can simply add a few lines of configuration to our `rollup.config.js` and `package.json`
##### rollup.config.js
-```javascript
+```js
output: [
...
{