2017-08-21 43 views
0

後正常工作後,我上傳的網站在XAMPP的虛擬主機愛可信方法停止工作(但網站運作良好)laravel VUE - 愛可信的方法不能上傳項目

的httpd的虛擬主機:

NameVirtualHost *:80 
<VirtualHost *:80> 
    DocumentRoot C:\xampp\htdocs\zbudWew\public 
    ServerName localhost 
    <Directory C:\xampp\htdocs\zbudWew\public> 
     Order allow,deny 
     Allow from all 
    </Directory> 
</VirtualHost> 

。 ENV:

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1 
DB_PORT=3306 
DB_DATABASE=zbudwew 
DB_USERNAME=root 
DB_PASSWORD= 

例如Axios的方法:

axios.post('api/news/', this.info).then(response => { 
         this.news.unshift(response.data.info); 
         this.info = {title: '', body:''}; 
         console.log(response.data); 

        }, response => { 
         this.errors = response.data; 
        }); 

在我的本地:8000地址的網站,並增加內容是工作不錯,但如果我想在我的192.168.0.199的地址添加內容,我得到錯誤:

[Vue warn]: Error in render function: "TypeError: Cannot read property 'title' of undefined" 

found in 

---> <Info> at C:\xampp\htdocs\zbudWew\resources\assets\js\components\Info.vue 
     <NewsManagement> at C:\xampp\htdocs\zbudWew\resources\assets\js\components\NewsManagement.vue 
     <Root> 

這是werid,因爲:

axios.get('api/news').then(response => { 
       this.news = response.data.news; 
      }); 

工作正常。你們可以給我一個建議如何解決這個問題嗎?

數據屬性和axios.post看起來是這樣的:

data() { 
     return { 
      show: false, 
      news: [], 
      errors: [], 
      info: { 
       title: '', 
       body: '', 
      } 
     } 
    }, components: { 
     Info 
    }, created() { 
     this.fetchNews(); 
    }, methods: { 
     fetchNews() { 
      axios.get('api/news').then(response => { 
       this.news = response.data.news; 
      }); 
     }, createInfo() { 
      axios.post('api/news/', this.info).then(response => { 
       this.news.unshift(response.data.info); 
       this.info = { 
        title: '', 
        body: '' 
       }; 
      }); 
     } 

信息組件看起來是這樣的:

<template> 
    <tr> 
     <td> 
      <span id="errorInfo"></span> 
      <input type="text" class="form-control" 
       v-model="editForm.title" v-if="edit" placeholder="Tytuł"> 
      <span v-else>{{ info.title }}</span> 
      <br> 
      <div v-if="edit"> 
       <textarea id="editorInfo" name="editorInfo" type="text" class="form-control" 
        v-model="editForm.body" ></textarea> 
      </div> 
      <span v-else></span> 

     </td> 


     <td align="right"> 
      <button v-on:click="editInfo" type="button" class="btn btn-info" 
       v-if="!edit" 
      >Edytuj</button> 
      <button v-on:click="$emit('delete-info', info)" type="button" class="btn btn-danger" 
       v-if="!edit">Usuń</button> 


      <button v-on:click="updateInfo(info, editForm)" type="button" class="btn btn-primary" 
       v-if="edit" 
      >Gotowe</button> 
      <button v-on:click="cancelEdit" type="button" class="btn btn-default" 
       v-if="edit" 
      >Anuluj</button> 
     </td> 
    </tr> 
</template> 

<script> 
    export default { 
     props: ['info'], 
     data(){ 
      return { 
       edit: false, 
       editForm:{ 
        title: '', 
        body:'' 
       } 
      } 
     }, 
     methods: { 
      editInfo(){ 
       this.edit = true; 
       this.editForm.title = this.info.title; 
       this.editForm.body = this.info.body; 
       window.setTimeout(function(){ 
        try{ 
         CKEDITOR.replace('editorInfo'); 
        }catch(e){} 
       }, 1); 
       $('#errorInfo').html(''); 
      }, 
      cancelEdit(){ 
       this.edit = false; 
       this.editForm.title = ''; 
       this.editForm.body = ''; 
       $('#errorInfo').html(''); 
      }, 
      updateInfo(oldUser, newUser){ 


       newUser.body = CKEDITOR.instances.editorInfo.getData(); 
       $('#errorInfo').html(''); 
       if (newUser.body == '' || newUser.title == ''){ 
        if(newUser.body == ''){ 
         $('#errorInfo').append('Treść jest wymagana i nie może być pusta.<br>'); 
        } 

        if(newUser.title == ''){ 
         $('#errorInfo').append('Tytuł jest wymagany i nie może być pusty.'); 
        } 
       } else { 

        axios.patch('/api/news/' + oldUser.id, newUser).then(response=> 
        { 
         this.$emit('update-info'); 
         this.cancelEdit(); 
         console.log(response.data); 
        }); 

       } 
      } 
     } 
    } 
</script> 


<style> 
#errorInfo { 
    color: #660000; 
} 
</style> 
+0

您問題中的代碼不會產生該錯誤消息。你在哪裏試圖訪問'title'屬性? – Phil

+0

這裏:'<輸入佔位符= 「Tytuł..」 類型= 「文本」 V-模型= 「info.title」 類= 「形式控制」>'其中'信息:{ \t \t \t \t \t標題:「 」, \t \t \t \t \t體: '', \t \t \t \t}' –

+0

什麼是你'data'屬性是什麼樣子?你的'axios.post'運行在哪裏? – Phil

回答

0

我解決的問題!

首先,我需要在我的web.php文件單獨的方法是這樣的:

Route::post('/api/newsAdd', '[email protected]'); 

那是以前:

Route::resource('api/news', 'NewsController'); 

Sedcondly有帶斜線問題:

前:axios.post('api/newsAdd/', this.info)

之後:axios.post('api/newsAdd', this.info)