You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Vue Hotel Datepicker组件报错:Failed to mount component: template/render函数未定义

Fixing "Failed to mount component: template or render function not defined" for Vue Hotel Datepicker

Let's walk through what's causing this error and fix it up quickly:

1. You've got a broken template tag

First off, your closing tag for the datepicker is totally malformed. </<HotelDatePicker> isn't valid HTML—you either use a self-closing tag like <HotelDatePicker/> or a properly paired closing tag like <HotelDatePicker></HotelDatePicker>. Vue gets tripped up by invalid template syntax, which is probably contributing to the render function error.

2. Component registration might be off

When you load the UMD version of the datepicker via a <script> tag, it attaches the component to the global window object. Your current code tries to register HotelDatePicker locally, but if Vue can't find that variable in scope, it throws the error you're seeing.

Corrected Code

Here's the fixed version of your index.html with explanations of the changes:

<html>
<head>
  <!-- Double-check that your Vue.js path points to the actual file -->
  <script src="path/to/vue.js"></script>
  <!-- Make sure this path is correct too—if you're using a CDN, replace it with the CDN URL -->
  <script src="vue-hotel-datepicker/dist/vue-hotel-datepicker.min.js"></script>
</head>
<body>
<div id="app">
  <!-- Using kebab-case for the component tag is Vue's recommended convention -->
  <hotel-date-picker></hotel-date-picker>
</div>
<script>
new Vue({
  el: '#app',
  components: {
    // Explicitly reference the global component from window
    HotelDatePicker: window.HotelDatePicker
  }
})
</script>
</body>
</html>

Key Fixes:

  • Valid Template: Replaced the broken closing tag with a properly formatted one, using kebab-case (Vue converts PascalCase component names to kebab-case in templates automatically).
  • Global Component Reference: Added window.HotelDatePicker to tell Vue exactly where to find the component. Alternatively, you could even remove the components option entirely—the UMD build usually registers the component globally, so Vue will pick it up without local registration.
  • Cleaner Structure: Moved scripts to the <head> (you could also put them right before </body>—just make sure Vue loads before the datepicker script).

One last thing: Double-check that your script paths are correct! If Vue or the datepicker script isn't loading properly, you'll get the same error.

内容的提问来源于stack exchange,提问作者BR Sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:41:42