File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 1212 <VueLive :code =" codeJs" :layout =" CustomLayout" />
1313 <h2 >Use the requires prop to make libraries and packages available in the browser</h2 >
1414 <VueLive :code =" codeChicago" :layout =" CustomLayout" :requires =" chicagoRequires" />
15+ <h2 >With a custom update delay of 2 seconds</h2 >
16+ <VueLive
17+ :code =" `<input type='button' value='update me' />`"
18+ :layout =" CustomLayout"
19+ :delay =" 2000"
20+ />
1521 <h2 >Default Layout</h2 >
1622 <div style =" width :950px ; width :950px ; max-width :95vw ; margin :20px auto ;" >
17- <VueLive :code =" `<input type='button' value='I am Groot'>`" />
23+ <VueLive :code =" `<input type='button' value='I am Groot' / >`" />
1824 </div >
1925 <link href =" https://fonts.googleapis.com/css?family=Roboto+Mono" rel =" stylesheet" >
2026 </main >
Original file line number Diff line number Diff line change @@ -69,13 +69,21 @@ export default {
6969 requires: {
7070 type: Object ,
7171 default : () => {}
72+ },
73+ /**
74+ * Time in ms debouncing updates to the preview
75+ */
76+ delay: {
77+ type: Number ,
78+ default: UPDATE_DELAY
7279 }
7380 },
7481 data () {
7582 return {
7683 model: this .code ,
7784 prismLang: " html" ,
7885 VueLiveDefaultLayout,
86+ updatePreview : () => {},
7987 /**
8088 * this data only gets changed when changing language.
8189 * it allows for copy and pasting without having the code
@@ -84,6 +92,11 @@ export default {
8492 stableCode: this .code
8593 };
8694 },
95+ beforeMount () {
96+ this .updatePreview = debounce (value => {
97+ this .model = value;
98+ }, this .delay );
99+ },
87100 computed: {
88101 codeKey () {
89102 return hash (this .model );
@@ -96,10 +109,7 @@ export default {
96109 this .prismLang = newPrismLang;
97110 this .stableCode = this .model ;
98111 }
99- },
100- updatePreview: debounce (function (value ) {
101- this .model = value;
102- }, UPDATE_DELAY )
112+ }
103113 }
104114};
105115 </script >
You can’t perform that action at this time.
0 commit comments