1. Use the life cycle hook function
# Backend code--Use pywebviewclass Api: def greet(self): greet_text= 'pywebview and vue3' response = {} response['text'] = greet_text return response if __name__ == '__main__': # Front-end communication test api = Api() window = webview.create_window('Vue app in pywebview', './static/', js_api=api) (debug=True)
<template> <div>{{ data }}</div> </template> <script> export default { data() { return { data: null }; }, created() { (); }, methods: { fetchData() { // Use pywebview front and backend communication ().then(response=> { = response['text']; }); } } }; </script>
2. Use the timer
<template> <div>{{ data }}</div> </template> <script> export default { data() { return { data: null, timer: null }; }, created() { (); = setInterval(, 5000); // Get data every 5 seconds }, methods: { fetchData() { // Use pywebview front and backend communication ().then(response=> { = response['text']; }); }, cancelAutoUpdate() { clearInterval(); } }, beforeDestroy() { (); } }; </script>
This is the article about how to automatically obtain data when Vue3 accesses a page. For more information about automatically obtaining data when Vue3 accesses a page, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!