简体   繁体   English

为什么我的嵌套 Vue 模板文件不渲染?

[英]Why don't my nested Vue template files render?

I have three main Vue files:我有三个主要的 Vue 文件:

index.vue.js: index.vue.js:

<template>
  <div class="tax-map-wrapper">
    <h1>this is the page the map renders</h1>
    <Map/>
  </div>
</template>

<script>
  import Map from './components/Map.vue';
  export default {

  }
</script>

Map.vue:地图.vue:

<template>
  <div>
    <h1>MAP TESTER</h1>
  </div> 
</template>

<script>
  console.log("map")
  import Pagination from './Pagination.vue';
  import { debounce } from '../helpers/util.js'
  export default {

  }
</script>

<style scoped></style>

Map.vue:地图.vue:

<template>
  <div>
    <h1>MAP TESTER</h1>
  </div>
</template>

<script>
  console.log("pagination")
  export default {
  }
</script>

<style scoped></style>

When my app loads up, I can see the "this is the page the map renders" in my browser, meaning the index.vue file is fine, it's template content shows up on the bowser.当我的应用程序加载时,我可以在浏览器中看到“这是地图呈现的页面”,这意味着 index.vue 文件很好,它的模板内容显示在 bowser 上。

However, when the Map component never renders, and neither does the Pagination nested within the Map.vue template file.但是,当 Map 组件从不渲染时,Pagination 也不会嵌套在 Map.vue 模板文件中。 In my console, I can see the console logs for both "map" and "pagination", meaning those files are getting hit.在我的控制台中,我可以看到“地图”和“分页”的控制台日志,这意味着这些文件正在被命中。 However, the templates associated with those two files are not rendered.但是,不会呈现与这两个文件关联的模板。 The borwser doesn't show any errors. borwser 没有显示任何错误。 It's just blank under the "this is the page the map page renders".在“这是地图页面呈现的页面”下它只是空白。

This is my tax_map.js:这是我的 tax_map.js:

import Vue from 'vue';
import Map from '../tax_map/index.vue';

Vue.use(Map)
document.addEventListener('DOMContentLoaded', () => {
  new Vue({
    el: '#tax-map-wrapper',
    render: h => h(Map)
  })

}) })

This is my tax_map.html.erb:这是我的 tax_map.html.erb:

<%= javascript_pack_tag 'tax_map' %>
<div id="tax-map-wrapper"></div>

Anyone know why the components within index.vue does not render?任何人都知道为什么 index.vue 中的组件不渲染? Any help is appreciated, thank you!任何帮助表示赞赏,谢谢!

In index.vue.js your code makes use of the Map component ( consider changing this because it shadows Javascript Map object );index.vue.js ,您的代码使用了 Map 组件(考虑更改它,因为它会隐藏Javascript Map 对象); it doesn't register it though.它虽然没有注册它。

You can find documentation on local registration of components when using build systems like Webpack to write Vue apps.在使用 Webpack 等构建系统编写 Vue 应用程序时,您可以找到有关组件本地注册的文档

In the module exports for index.vue , register Map as a component.index.vue的模块导出中,将Map注册为组件。

<script>
  import Map from './components/Map.vue';
  export default {
    components: {
      Map
    }
  }
</script>

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

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