{"[vue]":{// Defines a default formatter which takes precedence over all other formatter settings. Must be the identifier of an extension contributing a formatter."editor.defaultFormatter":"octref.vetur"},"[javascript]":{// Language Features for TypeScript and JavaScript files"editor.defaultFormatter":"vscode.typescript-language-features"},// https://thesoreon.com/blog/how-to-set-up-eslint-with-typescript-in-vs-code"eslint.validate":["javascript","javascriptreact"],// https://vuejs.github.io/vetur/formatting.html#formatters"vetur.format.defaultFormatter.js":"vscode-typescript","vetur.format.defaultFormatter.html":"js-beautify-html","vetur.format.defaultFormatterOptions":{"js-beautify-html":{"wrap_attributes":"force-expand-multiline"}},//为了符合eslint的两个空格间隔原则"editor.tabSize":2,// Error Checking"vetur.validation.template":false,// Configure glob patterns for excluding files and folders."files.exclude":{"node_modules":true},// Ignores the warning when there are too many changes in a repository."git.ignoreLimitWarning":true,// Code action kinds to be run on save."editor.codeActionsOnSave":{"source.fixAll.eslint":true},"git.confirmSync":false,// Report errors only , Suppress report warning"eslint.quiet":true,// Defines space handling before function argument parentheses."javascript.format.insertSpaceBeforeFunctionParenthesis":true,"typescript.format.insertSpaceAfterConstructor":true,"typescript.format.insertSpaceBeforeFunctionParenthesis":true,// Preferred quote style to use for quick fixes: `single` quotes, `double` quotes, or `auto` infer quote type from existing imports. Requires using TypeScript 2.9 or newer in the workspace."javascript.preferences.quoteStyle":"single","javascript.format.insertSpaceAfterConstructor":true,"typescript.preferences.quoteStyle":"single",// Wrap attributes.// - auto: Wrap attributes only when line length is exceeded.// - force: Wrap each attribute except first.// - force-aligned: Wrap each attribute except first and keep aligned.// - force-expand-multiline: Wrap each attribute.// - aligned-multiple: Wrap when line length is exceeded, align attributes vertically.// - preserve: Preserve wrapping of attributes// - preserve-aligned: Preserve wrapping of attributes but align."html.format.wrapAttributes":"force-expand-multiline",// Format a file on save. A formatter must be available, the file must not be saved after delay, and the editor must not be shutting down."editor.formatOnSave":true,// Whether or not to indent the code inside <script> and <style> tags in Vue files."prettier.vueIndentScriptAndStyle":false,"prettier.singleQuote":true,"prettier.useTabs":true}
<!-- parent --><base-layout><templatev-slot:header><h1>Here might be a page title</h1></template><p>A paragraph for the main content.</p><p>And another one.</p><template#footer><p>Here's some contact info</p></template></base-layout><!-- child --><template><divclass="container"><divclass="d1"><slotname="header"></slot><slot></slot><slotname="footer"></slot></div><divclass="d2"><CustomHeader><slotname="header"></slot></CustomHeader><main><slot></slot></main><footer><slotname="footer"></slot></footer></div></div></template><script>import CustomHeader from'./header'exportdefault{
components:{
CustomHeader
}}</script><stylescoped>.d1{background: red;}.d2{background: green;}</style>
2.3 作用域插槽
插槽内容能够访问子组件数据
插槽 prop : 绑定在 元素上的 attribute
解构插槽 Prop
动态插槽名
<containertitle="作用域插槽"><current-user><templatev-slot:default="slotProps">
{{ slotProps.user.firstName }}
</template></current-user><current-user>222</current-user><current-user></current-user><current-userv-slot="slotProps">
独占默认插槽的缩写语法:{{ slotProps.user.firstName }}
</current-user><current-user><templatev-slot:default="slotProps">
{{ slotProps.user.firstName }} /
</template><templatev-slot:other="{ other }">
{{other}}
</template><template#[dynamicSlotName]></template></current-user></container><template><div><slot:user="user">{{ user.lastName }}</slot><slotname="other":other="other">i am other default</slot></div></template><script>exportdefault{data(){return{
user:{
lastName:'jack',
firstName:'son'},
other:'i am other'}}}</script>
2.4 其它示例
插槽 prop 允许我们将插槽转换为可复用的模板
可设计封装数据逻辑同时允许父级组件自定义部分布局的可复用组件
<containertitle="其它示例"><todo-list:todos="todos"><template#todo="{ todo }"><spanv-if="todo.isComplete">✓</span>
{{ todo.text }}
</template></todo-list><todo-list:todos="todos"></todo-list></container><template><ul><liv-for="(todo,index) in todos":key="index"><!--
我们为每个 todo 准备了一个插槽,
将 `todo` 对象作为一个插槽的 prop 传入。
--><slotname="todo":todo="todo"><!-- 后备内容 -->
{{ todo.text }}
</slot></li></ul></template><script>exportdefault{
props:['todos']}</script>
Still provide succinct syntax for most common use cases of scoped slots
Clearer connection between scoped variable and the component that is providing it
Default slot with text
Nested default slots
Named slots
<template><div><containertitle="Default slot with text"><!-- old --><foo><templateslot-scope="{ msg }">
old1 : {{ msg }}
</template></foo><!-- new --><foov-slot="{ msg }">
new : {{ msg }}
</foo><!-- 有问题 --><!-- <foo slot-scope="{ msg }">
old2 : {{ msg }}
</foo> --></container><containertitle="Nested default slots"><!-- old --><foo><barslot-scope="foo"><bazslot-scope="bar"><templateslot-scope="baz">
{{ foo }} {{ bar }} {{ baz }}
</template></baz></bar></foo><!-- new --><foov-slot="foo"><barv-slot="bar"><bazv-slot="baz">
{{ foo }} {{ bar }} {{ baz }}
</baz></bar></foo></container><containertitle="Named slots"><!-- old --><foo><templateslot="one"slot-scope="{ msg }">
text slot: {{ msg }}
</template><divslot="two"slot-scope="{ msg }">
element slot: {{ msg }}
</div></foo><!-- new --><foo><templatev-slot:one="{ msg }">
text slot: {{ msg }}
</template><templatev-slot:two="{ msg }"><div>
element slot: {{ msg }}
</div></template></foo></container></div></template><script>import foo from'./foo'import bar from'./bar'import baz from'./baz'import container from'../container'exportdefault{
components:{
foo,
bar,
baz,
container
}}</script>
foo/baz/bar
<template><div>i am foo
<slot:msg="msg"></slot><slotname="one":msg="{msg: 1}"></slot><slotname="two":msg="{msg: 2}"></slot></div></template><script>exportdefault{data(){return{
msg:'foo'}}}</script><template><div>i am bar
<slot:msg="msg"></slot></div></template><script>exportdefault{data(){return{
msg:'bar'}}}</script><template><div>i am baz
<slot:msg="msg"></slot></div></template><script>exportdefault{data(){return{
msg:'baz'}}}</script>