|
12 | 12 | f.write("""<template> |
13 | 13 | <div id="vue-app"> |
14 | 14 | <h1>{{ message }}</h1> |
15 | | - <button @click="updateMessage">Click me!</button> |
| 15 | + <div> |
| 16 | + <button id="control-dash-button" @click="updateDash">Control Dash</button> |
| 17 | + </div> |
| 18 | + <div hidden> |
| 19 | + <button id="control-vue-button" @click="updateMessage">Control Vue</button> |
| 20 | + </div> |
16 | 21 | </div> |
17 | 22 | </template> |
18 | 23 |
|
|
21 | 26 |
|
22 | 27 | const message = ref("Hello from Vue!"); |
23 | 28 |
|
| 29 | +const updateDash = () => { |
| 30 | + message.value = "Hello from Vue!"; |
| 31 | + window.dash_clientside.set_props('dash-title', { children: 'Hello from Vue!' }); |
| 32 | +}; |
| 33 | +
|
24 | 34 | const updateMessage = () => { |
25 | | - message.value = "Vue is working!"; |
| 35 | + message.value = "Hello from Dash!"; |
26 | 36 | }; |
27 | 37 | </script> |
28 | 38 |
|
|
84 | 94 | build_assets_paths=['assets/js', 'assets/vue'], |
85 | 95 | entry_js_paths=['assets/js/main.js'], |
86 | 96 | npm_packages=[ |
87 | | - NpmPackage('vue'), # Removed version to use default/latest |
| 97 | + NpmPackage('vue'), |
88 | 98 | ], |
89 | | - clean_after=False, |
| 99 | + download_node=True, |
| 100 | + clean_after=True, |
90 | 101 | ) |
91 | 102 |
|
92 | 103 | # Call setup BEFORE creating Dash app (as required by the plugin architecture) |
|
104 | 115 | html.H1('Vite Plugin Test - Vue Support', id='header'), |
105 | 116 | html.P('This tests the Vite plugin with Vue support.', id='paragraph'), |
106 | 117 | # Container for Vue app |
107 | | - html.Div(id='vue-container'), |
108 | | - html.Div(id='vue-out'), |
109 | | - html.Div(id='js-test-result'), |
110 | | - html.Button('Test JS', id='js-test-button', n_clicks=0), |
111 | | - html.Button('Test Vue', id='vue-test-button', n_clicks=0), |
| 118 | + html.Div( |
| 119 | + [ |
| 120 | + 'The content from Vue', |
| 121 | + html.Div(id='vue-container'), |
| 122 | + ] |
| 123 | + ), |
| 124 | + html.Div( |
| 125 | + [ |
| 126 | + 'The content from Dash', |
| 127 | + html.Div( |
| 128 | + [html.H1('Hello from Dash!', id='dash-title'), html.Button('Control Vue', id='dash-button')], |
| 129 | + id='dash-app', |
| 130 | + style={'margin': '20px'}, |
| 131 | + ), |
| 132 | + ], |
| 133 | + id='dash-container', |
| 134 | + ), |
112 | 135 | ] |
113 | 136 | ) |
114 | 137 |
|
115 | | -# Add callback to test JavaScript execution |
116 | | -app.clientside_callback( |
117 | | - """ |
118 | | - function(n_clicks) { |
119 | | - if (n_clicks > 0) { |
120 | | - // Test if global variable exists |
121 | | - if (typeof window.testVariable !== 'undefined' && window.testVariable === 'VitePluginVueTest') { |
122 | | - return 'JavaScript behavior is working correctly'; |
123 | | - } else { |
124 | | - return 'Global variable test failed'; |
125 | | - } |
126 | | - } |
127 | | - return 'Click button to test JavaScript'; |
128 | | - } |
129 | | - """, |
130 | | - Output('js-test-result', 'children'), |
131 | | - Input('js-test-button', 'n_clicks'), |
132 | | -) |
133 | 138 |
|
134 | 139 | # Add callback to test Vue functionality with a simpler approach |
135 | 140 | app.clientside_callback( |
136 | 141 | """ |
137 | | - async function(n_clicks) { |
138 | | - function delay(ms) { |
139 | | - return new Promise(resolve => setTimeout(resolve, ms)); |
140 | | - } |
141 | | - async function testVueApp() { |
142 | | - const vueApp = document.getElementById('vue-app'); |
143 | | - if (vueApp) { |
144 | | - const button = vueApp.querySelector('button'); |
145 | | - if (button) { |
146 | | - const originalText = vueApp.querySelector('h1').textContent; |
147 | | - button.click(); |
148 | | - await delay(0); |
149 | | - const newText = vueApp.querySelector('h1').textContent; |
150 | | - if (newText === 'Vue is working!') { |
151 | | - return 'Vue is working correctly: ' + newText; |
152 | | - } else { |
153 | | - throw new Error('Vue button click failed. Original: ' + originalText + ', New: ' + newText); |
154 | | - } |
155 | | - } else { |
156 | | - throw new Error('Vue button not found'); |
157 | | - } |
158 | | - } else { |
159 | | - throw new Error('Vue app not found'); |
160 | | - } |
161 | | - } |
162 | | - if (n_clicks > 0) { |
163 | | - try { |
164 | | - const result = await testVueApp(); |
165 | | - return result; |
166 | | - } catch (error) { |
167 | | - return error.message; |
| 142 | + function(n_clicks) { |
| 143 | + if (n_clicks > 0) { |
| 144 | + const vueApp = document.getElementById('vue-app'); |
| 145 | + if (vueApp) { |
| 146 | + const button = vueApp.querySelector('#control-vue-button'); |
| 147 | + if (button) { |
| 148 | + button.click(); |
| 149 | + return 'Hello from Dash!'; |
168 | 150 | } |
169 | 151 | } |
170 | | - return 'Click button to test Vue'; |
| 152 | + } |
| 153 | + return 'Hello from Dash!'; |
171 | 154 | } |
172 | 155 | """, |
173 | | - Output('vue-out', 'children'), |
174 | | - Input('vue-test-button', 'n_clicks'), |
| 156 | + Output('dash-title', 'children'), |
| 157 | + Input('dash-button', 'n_clicks'), |
175 | 158 | ) |
176 | 159 |
|
177 | 160 |
|
|
0 commit comments