Advertisement
Guest User

Basic Vue3 App

a guest
Nov 15th, 2021
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.99 KB | None | 0 0
  1. <html>
  2. <head></head>
  3. <body>
  4.     <div  id='testfunction' class="bg-dark">
  5.         <span v-html="globalFun2"></span>
  6.         <button v-on:click='randFun'>refresh</button>
  7.     </div>
  8.     <script type="text/javascript">
  9.         // alias to fix missing console.info
  10.         console.info = function(text) {
  11.             console.log(text)
  12.         }
  13.     </script>
  14.     <!-- include vue 3 -->
  15.     <script src="https://unpkg.com/vue@next"></script>
  16.     <!-- simple Vue3 app -->
  17.     <script type="text/javascript">
  18.         const appFunction = Vue.createApp({
  19.             data(){
  20.                 return {
  21.                     globalFun1:'hello fun 1',
  22.                     globalFun2:'<h2>hello fun 2</h2>',
  23.                     textFun:''
  24.                 }
  25.             },
  26.             methods:{
  27.                 randFun(){
  28.                     const rand = Math.random();
  29.                     if (rand <= 0.5){
  30.                         alert(this.globalFun1)
  31.                     }else{
  32.                         alert(this.globalFun2);
  33.                     }
  34.                 }
  35.             }
  36.         })
  37.  
  38.         appFunction.mount('#testfunction');
  39.     </script>
  40. </body>
  41. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement