【问题标题】:How to use template inside template using vue.js & laravel?如何使用 vue.js 和 laravel 在模板中使用模板?
【发布时间】:2018-08-29 01:51:43
【问题描述】:

在我的项目中使用 laravel elixir 来混合 JavaScript 文件。

在表单中,我必须使用主 Vue.js 元素来创建表单。另外我必须在父 Vue.js 元素中使用 vue-google-map 模板,但它显示错误?

window.VueGoogleMaps = require('vue2-google-maps');
var app = new Vue({
    el: '#participantLocationListApp',
});

HTML:

<div class="panel panel-default card-view panel-refresh" id="participantLocationListApp">
    <template>
        <gmap-map:center="center" :zoom="1" style="width: 100%; height: 400px"> </gmap-map>
    </template>
</div>

错误:

[Vue 警告]:未知的自定义元素:&lt;gmap-map&gt; - 您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。

[Vue 警告]:未知的自定义元素:&lt;gmap-info-window&gt; - 您是否正确注册了组件?对于递归组件,请确保提供“名称”选项。

【问题讨论】:

  • 你的代码怎么样?
  • JS:window.VueGoogleMaps = require('vue2-google-maps'); var app = new Vue({ el: '#participantLocationListApp',}) HTML:&lt;div class="panel panel-default card-view panel-refresh" id="participantLocationListApp"&gt;&lt;template &gt; &lt;gmap-map:center="center" :zoom="1" style="width: 100%; height: 400px"&gt; &lt;/gmap-map&gt;&lt;/template&gt;&lt;/div&gt;
  • @OshosanyaMichael

标签: vue.js vuejs2 laravel-5.4 vue-component laravel-elixir


【解决方案1】:

您只是在声明插件。 You have to "use" it,所以 Vue 知道。

另外,&lt;template&gt; 毫无意义,你不希望它在那里。

应该是这样的:

在 JavaScript 代码中,激活插件through .use()

var VueGoogleMaps = require('vue2-google-maps');

// from the docs: https://www.npmjs.com/package/vue2-google-maps#with-npm-recommended
Vue.use(VueGoogleMaps , {
  load: {
    key: 'YOUR_API_TOKEN',
    v: '3.26',                // Google Maps API version
    // libraries: 'places',   // If you want to use places input
  }
});

var app = new Vue({
    el: '#participantLocationListApp',
})

HTML(去掉&lt;template&gt;):

<div class="panel panel-default card-view panel-refresh" id="participantLocationListApp">
    <gmap-map :center="center" :zoom="1" style="width: 100%; height: 400px"></gmap-map>
</div>

【讨论】:

  • 谢谢。控制台错误已清除但地图未显示&lt;iframe frameborder="0" src="about:blank" style="z-index: -1; position: absolute; width: 100%; height: 100%; top: 0px; left: 0px; border: none;"&gt;&lt;/iframe&gt;
  • 仔细检查地图声明、API 密钥、版本。它现在真的应该可以工作了。
  • 进展如何?
猜你喜欢
  • 2017-02-18
  • 2021-07-19
  • 2017-07-28
  • 2018-07-26
  • 2020-01-11
  • 2016-03-18
  • 2015-09-07
  • 2017-09-16
  • 2016-06-06
相关资源
最近更新 更多