繁体   English   中英

在 Firebase 托管上托管 Vue

[英]Host Vue on Firebase Hosting

我正在尝试在 Firebase 上使用此代码托管,但它不起作用。 {{Item.name}}出现而不是值 :( 我已经在 Codepen 上测试了相同的代码并且它有效。firebase接受vue.min.js吗?部署时,站点显示 {{var}} 而不是Google 表格中的表格值。

我正在尝试在 Firebase 上使用此代码托管,但它不起作用。 {{Item.name}}出现而不是值 :( 我已经在 Codepen 上测试了相同的代码并且它有效。firebase接受vue.min.js吗?部署时,站点显示 {{var}} 而不是Google 表格中的表格值。

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>






<script>
   var app = new Vue({
    el: '#app',
    mounted() {
        let vm = this
        axios
            .get(
                'https://sheets.googleapis.com/v4/spreadsheets/{sheetsID}/values/A2:C20?key={apiKey}'
            )
            .then(function (response) {
                let specials = response.data.values
                for (let index = 0; index < specials.length; index++) {
                    const element = specials[index]
                    let mitem = {
                        name: element[0],
                        description: element[1],
                        price: element[2]
                    }
                    if (vm.isEven(index)) {
                        vm.menuItems_L = vm.menuItems_L.concat(mitem)
                    } else {
                        vm.menuItems_R = vm.menuItems_R.concat(mitem)
                    }
                }
                console.log(response)
            })
    },
    data: {
        menuItems_L: [],
        menuItems_R: [],
        menuStyle: {
            background: '#f2f2f2',
            color: '#000'
        }
    },
    computed: {},
    methods: {
        isEven: function (n) {
            return n % 2 == 0
        }
    }
});
</script>

<body> :

<div id="app">
      <section id="specialssection" class="specials-container" v-if="menuItems_L" :style="menuStyle">
          <div id="special_component" :style="menuStyle">

              <div class="specials-table-container">
                  <table>
                      <tbody v-for="item in menuItems_L" :key="item.name">
                          <tr class="nameandprice">
                              <td>
                                  <span :style="menuStyle">{{item.name}}</span>
                              </td>
                              <td>
                                  <span :style="menuStyle">R${{item.price}}</span>
                              </td>
                          </tr>
                          <tr class="description">
                              <td colspan="2">{{item.description}}</td>
                          </tr>
                      </tbody>
                  </table>
                  <table>
                      <tbody v-for="item in menuItems_R" :key="`specialmenu-${item.name}`">
                          <tr class="nameandprice">
                              <td>
                                  <span :style="menuStyle">{{item.name}}</span>
                              </td>
                              <td>
                                  <span :style="menuStyle">${{item.price}}</span>
                              </td>
                          </tr>
                          <tr class="description">
                              <td colspan="2">{{item.description}}</td>
                          </tr>
                      </tbody>
                  </table>
              </div>
          </div>
      </section>
    </div>

看起来唯一错误的是标签的顺序。

你只需要在<div id="app">标签加载到 DOM 后运行 vue 代码。 下面是一个例子:

<html>
<head>
 <!-- Include all CDN scripts here -->
</head>

<body>
 <div id="app" >
 </div>

 <script>
   // Needs to be called after the <div id="app"> tag is loaded into the DOM
   var app = new Vue({
    el: '#app',
    ...
   })
 </script>
</body>


</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM