File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed
Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change 11<template >
22 <div >
3+ <div >
4+ <h3 >Dynamically update code:</h3 >
5+ <textarea v-model =" dynamicCode" ></textarea >
6+ <code-highlight >
7+ {{dynamicCode}}
8+ </code-highlight >
9+ </div >
10+
11+ <hr />
12+
313 <code-highlight >
414 let isPalindrome = (word) => {
515 let [length, result] = [word.length, true];
@@ -25,7 +35,9 @@ export default {
2535 CodeHighlight,
2636 },
2737 data () {
28- return {};
38+ return {
39+ dynamicCode: ' <div>Type here to see me change below</div>'
40+ };
2941 },
3042};
3143 </script >
@@ -38,6 +50,10 @@ body {
3850 justify-content : center ;
3951 align-items : center ;
4052}
53+ textarea {
54+ width :400px ;
55+ height :200px ;
56+ }
4157@import ' ../themes/duotone-sea.css' ;
4258@import ' ../themes/window.css' ;
4359 </style >
Original file line number Diff line number Diff line change 11<template >
22<div ref =" codeBlock" >
3- <pre :class =" languageClass" >
4- <code >
5- <slot ></slot >
6- </code >
7- </pre >
3+ <pre :class =" languageClass" ><code ><slot /></code ></pre >
84</div >
95</template >
106
@@ -27,5 +23,11 @@ export default {
2723 mounted () {
2824 Prism .highlightAllUnder (this .$refs .codeBlock );
2925 },
26+
27+ beforeUpdate () {
28+ const newText = this .$slots .default [0 ].text .replace (/ ^ [\r\n\s ] * | [\r\n\s ] * $ / g , " " );
29+ this .$el .querySelector (' code' ).textContent = newText;
30+ Prism .highlightAllUnder (this .$refs .codeBlock );
31+ }
3032};
3133 </script >
You can’t perform that action at this time.
0 commit comments