2017-06-14 113 views
0

我得到以下運行時錯誤時,彈性搜索與Vue.js,誤差遺漏的類型錯誤集成無法讀取的未定義的屬性「原型」 app.js:1173),:4990:31)。這個問題發生在所有的瀏覽器遺漏的類型錯誤:在EVAL無法讀取的未定義的屬性「原型」(EVAL在(:在EVAL

elastic_search.js 
var es = require('elasticsearch') 
var port = 9200 
var protocol = 'http' 
var hosturl = [ '127.0.0.1'] 
var hosts = hosturl.map (function(host) { 
    return{ 
    protocol : protocol, 
    host : host, 
    port : port 
    } 
}) 

var client = new es.Client({ 
    hosts: hosts 
}) 

export function search() { 
    alert('hell1') 
    return client.search({ 
    index: 'logstash-2017.06.07', 
    type: 'logs', 
    body: { 
     query: { 
     match_all: {} 
     } 
    } 
    }).then(function (resp) { 
    return resp.hits.hits 
    }, function (err) { 
    console.trace(err.message) 
    }) 
} 

main.js 
import Vue from 'vue' 
import App from './App' 
import router from './router' 
Vue.use(require('vue-resource')) 
import {search} from './elastic_search.js' 
Vue.config.productionTip = false 

/* eslint-disable no-new */ 
var handler = new Vue({ 
    el: '#app', 
    router, 
    template: '<App/>', 
    components: { App }, 
    methods: { 
    search: function() { 
    search().then(function (res) { 
     alert(res) 
     }) 
    } 
    } 
    }) 
handler.search() 

回答

0

在這種情況下, 你將不得不到彈性搜索包本身之前安裝彈性搜索的類型定義。

我的角度-2開發者和使用類似的命令對這個問題的角度-2或4

卸載,如果已經做了彈性搜索的所有包,這樣一個有效的解決方案......

 
npm uninstall elasticsearch 
npm uninstall -g elasticsearch 
npm uninstall -g --save-dev elasticsearch 
npm uninstall @types/elasticsearch 

現在使用角CLI在項目中安裝了彈性搜索包的類型定義

 
npm install @types/elasticsearch 

現在安裝彈性搜索包

 
npm install elasticsearch 

希望你能和它聯繫起來。

相關問題