2017-01-06 17 views
0

我嘗試在我的laravel 5.3項目中添加http://gritcode.github.io/gritcode-components/#/wizard但是當我在我看來,利用其沒有在這裏展示的是我得到控制檯「未捕獲的ReferenceError:gritcode沒有定義」 我app.js是。如何在我的laravel5.3項目中添加這個外部vue組件?

require('./bootstrap'); 
Vue.component('example', require('./components/Example.vue')); 
new Vue({ components: { 'vs-toast': gritcode-components.toast }}) 

const app = new Vue({ 
el: '#app', 
}); 

和我welcome.blade.php

<div id="app"> 

    <vs-toast> 

     <vs-wizard :current-index.sync="currentStep"> 
     <vs-wizard-step 
     title="Personal Information" 
     description="Enter your details" 
     :progress="progress.step1" 
     icon="person"> 
     </vs-wizard-step> 
     <vs-wizard-step 
     title="Payment" 
     description="Pay with credit card or Paypal" 
     :progress="progress.step2" 
     icon="credit-card"> 
     </vs-wizard-step> 
     <vs-wizard-step 
     title="Confirmation" 
     description="Your order details" 
     :progress="progress.step3" 
     :disable-previous="true" 
     icon="check"> 
     </vs-wizard-step> 
    </vs-wizard> 

    </vs-toast> 

</div> 

我的package.json

{ 
    "private": true, 
    "scripts": { 
    "prod": "gulp --production", 
    "dev": "gulp watch" 
    }, 
    "devDependencies": { 
    "babel": "^6.5.2", 
    "babel-core": "^6.21.0", 
    "babel-loader": "^6.2.10", 
    "babel-preset-es2015": "^6.18.0", 
    "bootstrap-sass": "^3.3.7", 
    "gritcode-components": "^0.4.7", 
    "gulp": "^3.9.1", 
    "jquery": "^3.1.0", 
    "laravel-elixir": "^6.0.0-9", 
    "laravel-elixir-vue-2": "^0.2.0", 
    "laravel-elixir-webpack-official": "^1.0.2", 
    "lodash": "^4.16.2", 
    "vue": "^2.0.1", 
    "vue-resource": "^1.0.3", 
    "vuestrap-base-components": "^0.8.10", 
    "webpack": "^1.14.0" 
    }, 
    "dependencies": { 
    "vue-material-datepicker": "^2.0.1" 
    } 
    } 

我gulpfile.js

const elixir = require('laravel-elixir'); 

     require('laravel-elixir-vue-2'); 



    elixir(mix => { 
     mix.sass('app.scss') 
     .webpack('app.js'); 
      }); 

回答

0

作爲例子說,在介紹頁面中,您必須從插件的子目錄導入它們。

在其網站上給出的例子是它有一個默認的出口,但他們的toast組件,因爲wizard是由兩個部分組成它使用命名的出口代替導入他們的語法是稍有不同的。

導入default出口

import foo from "someComponent" 

導入named出口

import {bar, baz} from "SomeOtherComponent" 

所以,你的情況,你應該能夠做到:

require('./bootstrap'); 

import {wizard, wizardStep} from "gritcode-components/src/components/wizard"; 

const app = new Vue({ 
    el: '#app', 
    components: { 
     'vs-wizard': wizard, 
     'vs-wizard-step': wizardStep 
    } 
}); 

希望這有助於!

+0

我越來越https://i.stack.imgur.com/R9lrS.png –

+0

@VipinKumar你能編輯你的問題的錯誤,並添加內容在你的'gulpfile.js'和'package.json'上? –

+0

我編輯的問題,當你說在回答我使用時,但我收到錯誤「您可能需要一個適當的加載程序來處理這種文件類型。」 –

0

我有類似的問題,這對我工作。

import { wizard as vsWizard } from 'gritcode-components/dist/gritcode-components'; 
import { wizardStep as vsWizardStep } from 'gritcode-components/dist/gritcode-components'; 
import { toast as vsToast } from 'gritcode-components/dist/gritcode-components'; 

注意,我們從 加載此「gritcode組件/距離/ gritcode組件」 不是從 「gritcode組件/ src目錄/組件/嚮導」的建議中的一個答案。

然後在Vue的情況下,你可以做這樣的事情來加載組件:

require('./bootstrap'); 

const app = new Vue({ 
    el: '#app', 
    components: { 
     vsWizard, 
     vsWizardStep, 
     vsToast 
    }, 
    data: { 
     currentStep: 0 
    }, 
    computed: { 
     progress: function() { 
      return { 
       step1: this.getStepPercentage(1), 
       step2: this.getStepPercentage(2), 
       step3: this.getStepPercentage(3) 
      }; 
     } 
    }, 
    methods: { 
     getStepPercentage: function(stepNumber) { 

       if (stepNumber == 1) { 
        //depending on your requirements you will return 
        //a value between 0 and 100 that describe 
        //the completion status of the step 1 
       } 

       if (stepNumber == 2) { 
        //depending on your requirements you will return 
        //a value between 0 and 100 that describes 
        //the completion status of the step 2 
       } 

       if (stepNumber == 3) { 
        //depending on your requirements you will return 
        //a value between 0 and 100 that describes the 
        //completion status of the step 3 
       } 

     } 
    } 
}); 

而且在你的問題,你有兩個Vue的實例:一個爲您加載組件,另外一種結合到id爲#app的元素。帶有#app元素的那個元素是將從刀片文件管理你的html的元素。你會遇到的,一旦這種代碼加載的問題是,您要添加未綁定到你的#APP DIV在Vue的實例的成分,因此指定用於管理#APP元素Vue的實例將不會有對它們的訪問。因此,我建議只使用上例中的Vue的一個實例,除非您有足夠的理由使用更多

最後,我建議您不要用'vs-toast'包裝'vs-wizard'標記元素,除非你想在你的麪包,顯示嚮導,我不知道是可能的。

你可以做這樣的事情,而不是:

<div id="app"> 

    <vs-toast></vs-toast> 

    <vs-wizard :current-index.sync="currentStep"> 
     <vs-wizard-step 
     title="Personal Information" 
     description="Enter your details" 
     :progress="progress.step1" 
     icon="person"> 
     </vs-wizard-step> 
     <vs-wizard-step 
     title="Payment" 
     description="Pay with credit card or Paypal" 
     :progress="progress.step2" 
     icon="credit-card"> 
     </vs-wizard-step> 
     <vs-wizard-step 
     title="Confirmation" 
     description="Your order details" 
     :progress="progress.step3" 
     :disable-previous="true" 
     icon="check"> 
     </vs-wizard-step> 
    </vs-wizard> 
</div> 
+0

vue.js?3de6:523 [Vue warn]:屬性或方法「currentStep」未在實例上定義,但在渲染過程中被引用。確保在數據選項中聲明反應數據屬性。 (在根實例中找到)我收到錯誤 –

+0

您必須將'currentStep'作爲數據添加到您的Vue實例。此外,您還必須創建「進度」計算屬性,以在完成嚮導中的每個步驟時向用戶提供反饋。此外,您需要某種輔助方法來計算每個步驟的完成百分比。如果您不需要步驟完成反饋,請從中刪除進度屬性。看看上面修改的答案,特別是Vue實例。 – Igor

相關問題