【问题标题】:VUEJS "Vue Hotel Datepicker" componentVUEJS“Vue 酒店日期选择器”组件
【发布时间】:2018-01-28 11:42:30
【问题描述】:

这是我想在我的 index.html 上使用 [https://krystalcampioni.github.io/vue-hotel-datepicker/] [https://github.com/krystalcampioni/vue-hotel-datepicker#i18n] 作为日期选择器的组件,但我给出了一个错误 无法安装组件:未定义模板或渲染函数。 下面是我在 index.html 上写的代码`

//index.html
<html>
    <script src="path/to/vue.js"></script> 
    <script src="vue-hotel-datepicker/dist/vue-hotel-datepicker.min.js"></script> 
    <body>
        <div id="app">
            <HotelDatePicker/></<HotelDatePicker>
        </div>
        <script>
            new Vue({
                el: '#app',
                components: { HotelDatePicker }
            })
        </script> 
    </body>
</html>

`

【问题讨论】:

  • 您必须为此使用require

标签: vue.js datepicker vuejs2 vue-component


【解决方案1】:

如果您使用的是构建工具,则必须先导入组件,然后再将其注册到 vue 实例中

import HotelDatePicker from 'vue-hotel-datepicker'

new Vue({
       el: '#app',
       components: { HotelDatePicker }
 })

否则使用require

new Vue({
     el: '#app',
     components: {
          'vue-hotel-datepicker': require('vue-hotel-datepicker')
     }
})

【讨论】:

  • 我觉得这行不通,浏览器不支持import,这是一种es6语法
  • 您是否使用构建工具来捆绑您的资源?
  • 显然他不是! (这不是我的问题)。如果他使用的是构建工具,那么即使使用这个组件库的 dist 版本也是不“明智的”。
  • 就是这样。假设“明智”的决策不会是“明智的”。
  • 不,我没有使用构建工具,它不在我的项目范围内。导入也不起作用
猜你喜欢
  • 2017-02-20
  • 2017-04-25
  • 1970-01-01
  • 2018-06-06
  • 1970-01-01
  • 2021-08-22
  • 2021-09-10
  • 2019-08-20
  • 1970-01-01
相关资源
最近更新 更多