Showing
3 changed files
with
51 additions
and
11 deletions
| ... | @@ -7,16 +7,16 @@ | ... | @@ -7,16 +7,16 @@ |
| 7 | </p> | 7 | </p> |
| 8 | <child :level="1">Hello world!</child> | 8 | <child :level="1">Hello world!</child> |
| 9 | <child :level="3">Hello world!</child> | 9 | <child :level="3">Hello world!</child> |
| 10 | + <my-paragraph></my-paragraph> | ||
| 10 | </div> | 11 | </div> |
| 11 | </template> | 12 | </template> |
| 12 | 13 | ||
| 13 | <script> | 14 | <script> |
| 14 | import counter from './components/counter.vue' | 15 | import counter from './components/counter.vue' |
| 15 | import child from './components/child.vue' | 16 | import child from './components/child.vue' |
| 17 | +import myParagraph from './components/myParagraph.vue' | ||
| 16 | 18 | ||
| 17 | -import { | 19 | +import { store } from './main.js' |
| 18 | - store | ||
| 19 | -} from './main.js' | ||
| 20 | 20 | ||
| 21 | export default { | 21 | export default { |
| 22 | name: 'app', | 22 | name: 'app', |
| ... | @@ -39,7 +39,7 @@ export default { | ... | @@ -39,7 +39,7 @@ export default { |
| 39 | } | 39 | } |
| 40 | }, | 40 | }, |
| 41 | components: { | 41 | components: { |
| 42 | - counter,child | 42 | + counter,child,myParagraph |
| 43 | } | 43 | } |
| 44 | } | 44 | } |
| 45 | </script> | 45 | </script> | ... | ... |
| 1 | <script> | 1 | <script> |
| 2 | +var getChildrenTextContent = function(children) { | ||
| 3 | + return children.map(function(node) { | ||
| 4 | + return node.children ? | ||
| 5 | + getChildrenTextContent(node.children) : | ||
| 6 | + node.text | ||
| 7 | + }).join('') | ||
| 8 | +} | ||
| 9 | + | ||
| 2 | export default { | 10 | export default { |
| 3 | data() { | 11 | data() { |
| 4 | return { | 12 | return { |
| 5 | 13 | ||
| 6 | } | 14 | } |
| 7 | }, | 15 | }, |
| 8 | - computed: { | 16 | + computed: {}, |
| 9 | - | 17 | + mounted() {}, |
| 10 | - }, | ||
| 11 | - mounted() { | ||
| 12 | - | ||
| 13 | - }, | ||
| 14 | methods: {}, | 18 | methods: {}, |
| 15 | components: {}, | 19 | components: {}, |
| 16 | render: function(createElement) { | 20 | render: function(createElement) { |
| 21 | + var headingId = getChildrenTextContent(this.$slots.default) | ||
| 22 | + .toLowerCase() | ||
| 23 | + .replace(/\W+/g, '-') | ||
| 24 | + .replace(/(^\-|\-$)/g, '') | ||
| 17 | return createElement( | 25 | return createElement( |
| 18 | 'h' + this.level, | 26 | 'h' + this.level, |
| 19 | - this.$slots.default | 27 | + [ |
| 28 | + createElement('a', { | ||
| 29 | + attrs: { | ||
| 30 | + name: headingId, | ||
| 31 | + href: '#' + headingId | ||
| 32 | + } | ||
| 33 | + }, this.$slots.default) | ||
| 34 | + ] | ||
| 20 | ) | 35 | ) |
| 21 | }, | 36 | }, |
| 22 | props: { | 37 | props: { | ... | ... |
src/components/myParagraph.vue
0 → 100644
| 1 | +<script> | ||
| 2 | +export default { | ||
| 3 | + data() { | ||
| 4 | + return {} | ||
| 5 | + }, | ||
| 6 | + computed: {}, | ||
| 7 | + mounted() {}, | ||
| 8 | + methods: {}, | ||
| 9 | + components: {}, | ||
| 10 | + render: function(createElement) { | ||
| 11 | + // var myParagraphVNode = createElement('p', 'hi') | ||
| 12 | + // return createElement('div', [ | ||
| 13 | + // // Yikes - duplicate VNodes! | ||
| 14 | + // myParagraphVNode, myParagraphVNode | ||
| 15 | + // ]) | ||
| 16 | + return createElement('div', | ||
| 17 | + Array.apply(null, { | ||
| 18 | + length: 10 | ||
| 19 | + }).map(function() { | ||
| 20 | + return createElement('p', 'hi') | ||
| 21 | + }) | ||
| 22 | + ) | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | +</script> |
-
Please register or login to post a comment