2017-06-19 73 views
1

我製作了一個自動完成組件,它在Chrome中運行良好,但在IE和Safari中無法運行。Vuejs 2顯示模板兩次IE和Safari刀片使用刀片

它在IE和Safari中顯示模板兩次。它可以工作,但它顯示了除了呈現的HTML之外的模板。看到圖片。

我做錯了什麼?

<div id="main"> 
    <autocomplete></autocomplete> 
</div> 

<template id="autocomplete"> 
    <div> 
     <div class="col"> 
      <section class="box clr1"> 
       <div> 
        <div> 
         <input type="text" placeholder="Welk product zoekt U?" v-model="query" v-on:keyup="autoComplete" class="form-control"> 
         <div class="panel-footer" v-if="results.length"> 
          <ul class="list-group"> 
           <li class="list-group-item" v-for="result in results"> 
            <span style="text-decoration: underline;cursor:pointer" v-on:click="showDetail(result.id)">@{{ result.title }}</span>... 

     <div class="col"> 
      <section class="box clr1"> 
       <div> 
        <div v-for="detail in resultdetail"> 
         <h1>@{{ detail.title }}</h1> 
         <h2>@{{ detail.page_title }}</h2> 
         <p v-html="detail.description"></p>... 


Vue.component('autocomplete', { 
     template: '#autocomplete', 
     data: function() { 
      return { 
       show: false, 
       query: '', 
       results: [], 
       resultdetail: [] 
      } 
     }, 
     methods: { 
      autoComplete: function() { 
       this.results = []; 
       if (this.query.length > 1) { 
        axios.get('/getproductjson/' + this.query + '/0') 
         .then(function (response) { 
          this.results = response.data 
         }.bind(this))... 
      showDetail: function (productId) { 
       if (productId > 0) { 

        this.show = true; 
        this.resultdetail = []; 
        axios.get('/getproductjson/loremipsumdipsum/'+productId) 
         .then(function (response) { 
          this.resultdetail = response.data 
         }.bind(this))... 
     } 
    }); 
    new Vue({ 
     el: '#main' 
    }); 

結果:

enter image description here

回答

1

Internet Explorer的does not supporttemplate標籤。

您在Internet Explorer中看到的是您實例化的Vue,並且由於IE不執行template,它只是在屏幕上顯示您的模板。

在IE中,如果要將模板存儲在DOM中,通常必須使用腳本模板。

<script type="text/x-template" id="autocomplete"> 
    ... 
</script>