0

私は比較的単純なlaravelアプリケーションを構築していて、Vue.jsを学びたいと思っていました...これは非常にイライラする混乱になっています...

とにかく、ここで問題です。何をしても、コンポーネントが定義されていないというエラーが表示されます。

これが私が持っているものです...

ガルプファイル

var elixir = require('laravel-elixir');
  require('laravel-elixir-vueify');

// Elixir Mixins.
elixir(function(mix) {
    mix.sass('app.scss');
    mix.browserify('main.js');
});

/resources/assets/js/main.js

   var Vue =  require('vue');
   var VueRouter = require('vue-router');
   Vue.use(VueRouter);
   import Form2016_1099_misc from './components/2016-1099-misc.vue';
   Vue.component('Form2016_1099_misc', Form2016_1099_misc);

私のブレードファイルでは...

@section('content')
  <div id="app">
    <h1>Hello App!</h1>
    <p>
      <!-- use v-link directive for navigation. -->
      <a v-link="{ path: '/recipient' }">Go to Recipient</a>
      <a v-link="{ path: '/form/2016/1099-misc' }">Go to 1099</a>
    </p>
    <!-- route outlet -->
    <router-view></router-view>
  </div>
@endsection

@section('footer')
  <script src="{{ asset('/js/main.js') }}"></script>

  <script>
    // Define some components
    var RecipientForm = Vue.extend({
      template: '<p>This is the recipient form.</p>'
    });
    var App = Vue.extend({});
    var router = new VueRouter();

    router.map({
      '/recipient': {
        component: RecipientForm
      },

      '/form/2016/1099-misc': {
        component: Form2016_1099_misc
      },
    });
    router.start(App, '#app');
  </script>
@endsection

/resources/assets/js/components/2016-1099-misc.vue

<template>
    {{ msg }}
</template>

<style>

</style>

<script>
    export default{
        data(){
            return{
                msg: 'This is a test'
            }
        }
    }
</script>

gulp を実行すると、正常に動作します。ブラウザでページを表示しようとすると、エラー メッセージが表示されます

ReferenceError: Form2016_1099_misc is not defined

私は間違ったことをたくさんしていると確信しています。私は Vue を初めて使用し、把握するのに苦労しています...

アップデート:

すべてのスクリプト コードをブレード ファイルから main.js ファイルに移動したところ、main.js は次のようになりました。

var Vue =  require('vue');
var VueRouter = require('vue-router');
use(VueRouter);
import Form2016_1099_misc from './components/2016-1099-misc.vue';
Vue.component('Form2016_1099_misc', Form2016_1099_misc);

// Define some components
var RecipientForm = Vue.extend({
  template: '<p>This is the recipient form.</p>'
});

var App = Vue.extend({});
var router = new VueRouter();

router.map({
  '/recipient': {
    component: RecipientForm
  },

  '/form/2016/1099-misc': {
    component: Form2016_1099_misc
  },


});

router.start(App, '#app');

エラーメッセージが表示されるようになりました

[Vue warn]: Failed to resolve directive: link (found in component: <router-app>)
[Vue warn]: Unknown custom element: <router-view> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
4

2 に答える 2

0

どうやらVueを2回ロードしていたようです。1 回は NPM から、もう 1 回は CDN から。CDNを削除したところ、正常に動作するようになりました...

于 2016-09-17T11:20:48.333 に答える