Advertisement
kref

Vue.js - PHP prerender

Jan 11th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.95 KB | None | 0 0
  1. <!doctype html>
  2. <html class="no-js" lang="">
  3. <head>
  4.     <meta charset="utf-8">
  5.     <meta http-equiv="x-ua-compatible" content="ie=edge">
  6.     <title>Vue</title>
  7.     <meta name="description" content="">
  8.     <meta name="viewport" content="width=device-width, initial-scale=1">
  9.  
  10.     <style>
  11.         body {
  12.             background: #20262E;
  13.             padding: 20px;
  14.             font-family: Helvetica;
  15.         }
  16.  
  17.         #boxes {
  18.             background: #fff;
  19.             border-radius: 4px;
  20.             padding: 20px;
  21.             transition: all 0.2s;
  22.         }
  23.  
  24.         section {
  25.             width: 100%;
  26.             display: flex;
  27.             flex-direction: row;
  28.             justify-content: space-between;
  29.         }
  30.  
  31.         .abc {
  32.             margin: 8px 0;
  33.             display: block;
  34.             padding: 20px;
  35.             border: 1px solid black;
  36.  
  37.         }
  38.  
  39.         h2 {
  40.             font-weight: bold;
  41.             margin-bottom: 15px;
  42.         }
  43.     </style>
  44. </head>
  45. <body>
  46.     <?php
  47.        $boxes = [
  48.            ["text" => "Learn JavaScript"],
  49.             ["text" => "Learn Vue"],
  50.             ["text" => "Play around in JSFiddle"],
  51.             ["text" => "Build something awesome"],
  52.         ];
  53.     ?>
  54.  
  55.     <div id="boxes">
  56.         <section>
  57.             <?php
  58.            foreach ($boxes as $key => $box) {
  59.                 echo '<box text="'.$box['text'].'"><div class="abc"><span>'.$box['text'].'</span></div></box>';
  60.             }
  61.             ?>
  62.         </section>
  63.     </div>
  64.  
  65.     <script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.js"></script>
  66.     <script>
  67.         Vue.component('box', {
  68.             data: function () {
  69.                 return {
  70.                     text: ""
  71.                 }
  72.             },
  73.             props: ['text'],
  74.             template: '<div class="abc"><span v-text="text"></span></div>'
  75.         });
  76.  
  77.         new Vue({ el: "#boxes" })
  78.     </script>
  79. </body>
  80. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement