Skip to content

Commit 4bcec63

Browse files
author
User
committed
added Options/DOM APIs
1 parent 27d30d0 commit 4bcec63

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

apis/optionsdom.js

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const EL = {
1010
name: 'el',
1111
type: 'string | HTMLElement',
1212
restriction: `only respected in instance created via ${colorArgs('new')}.`,
13-
details: `Provide the Vue instance an existing DOM element to mount on. It can be a CSS selector string or
14-
an actual HTMLElement. After the instance is mounted,
13+
details: `Provide the Vue instance an existing DOM element to mount on. It can be a CSS
14+
selector string or an actual HTMLElement. After the instance is mounted,
1515
the resolved element will be accessible as ${colorArgs('vm.$el')}.
1616
If this option is available at instantiation, the instance will immediately enter
1717
compilation; otherwise, the user will have to explicitly call ${colorArgs('vm.$mount()')} to manually
@@ -20,12 +20,61 @@ const EL = {
2020
mounted element will be replaced with Vue-generated DOM in all cases. It is therefore
2121
not recommended to mount the root instance to ${colorArgs('<html>')} or ${colorArgs('<body>')}.
2222
If neither ${colorArgs('render')} function nor ${colorArgs('template')} option is present, the in-DOM HTML of
23-
the mounting DOM element will be extracted as the template. In this case, Runtime + Compiler build of Vue should be used.`
23+
the mounting DOM element will be extracted as the template. In this case,
24+
Runtime + Compiler build of Vue should be used.`
2425
,
2526
}
26-
const TEMPLATE = {}
27-
const RENDER = {}
28-
const RENDER_ERROR = {}
27+
// untested
28+
const TEMPLATE = {
29+
category: 'Options/DOM',
30+
name: 'template',
31+
type: 'string',
32+
details: `A string template to be used as the markup for the Vue instance.
33+
The template will replace the mounted element. Any existing markup inside the mounted
34+
element will be ignored, unless content distribution slots are present in the template.
35+
If the string starts with ${colorArgs('#')} it will be used as a querySelector and use the selected element’s
36+
innerHTML as the template string. This allows the use of the common ${colorArgs(`<script type="x-template">`)}
37+
trick to include templates. From a security perspective, you should only use Vue templates
38+
that you can trust. Never use user-generated content as your template.
39+
If render function is present in the Vue option, the template will be ignored.
40+
41+
`
42+
}
43+
const RENDER = {
44+
category: 'Options/DOM',
45+
name: 'render',
46+
type: '(createElement: () => VNode) => VNode',
47+
details: `An alternative to string templates allowing you to leverage the full programmatic
48+
power of JavaScript. The render function receives a ${colorArgs('createElement')} method
49+
as it’s first argument used to create ${colorArgs('VNode')}s. If the component is a functional component,
50+
the render function also receives an extra argument ${colorArgs('context')}, which provides access to
51+
contextual data since functional components are instance-less.
52+
53+
The ${colorArgs('render')} function has priority over the render function compiled from ${colorArgs('template')} option
54+
or in-DOM HTML template of the mounting element which is specified by the ${colorArgs('el')} option.
55+
56+
`
57+
}
58+
const RENDER_ERROR = {
59+
category: 'Options/DOM',
60+
name: 'renderError',
61+
type: '(createElement: () => VNode, error: Error) => VNode',
62+
details: `${chalk.bold('Only works in development mode')}.
63+
Provide an alternative render output when the default ${colorArgs('render')} function encounters
64+
an error. The error will be passed to ${colorArgs('renderError')} as the second argument.
65+
This is particularly useful when used together with hot-reload`,
66+
example: `
67+
${colorArgs('new')} Vue({
68+
render (h) {
69+
${colorArgs('throw new')} ${chalk.green('Error')}(${chalk.green("'oops'")})
70+
},
71+
renderError (h, err) {
72+
${colorArgs('return')} h(${chalk.green("'pre'")}, { style: { color: ${chalk.green("'red'")} }}, err.stack)
73+
}
74+
}).$mount(${chalk.green("'#app'")})
75+
76+
`
77+
}
2978

3079

3180
module.exports = {

vue-help.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,22 @@ V.command('el', 'Options/DOM: #el').action(function(args, callback){
178178
const w = odom[0]
179179
this.log(O.logOptions(w))
180180
callback()
181+
})
182+
183+
V.command('template', 'Options/DOM: #template').action(function(args, callback){
184+
const w = odom[1]
185+
this.log(O.logOptions(w))
186+
callback()
187+
})
188+
189+
V.command('render', 'Options/DOM: #render').action(function(args, callback){
190+
const w = odom[2]
191+
this.log(O.logOptions(w))
192+
callback()
193+
})
194+
195+
V.command('renderError', 'Options/DOM: #renderError').action(function(args, callback){
196+
const w = odom[3]
197+
this.log(O.logOptions(w))
198+
callback()
181199
})

0 commit comments

Comments
 (0)