我使用webpack
,vue.js 2.0
和Laravel 5.3
。当我用gulp编译时没有出错。
但是当我转到指向console
的{{1}}时,我在/home
中收到此错误。
错误:
home.blade.php
app.js
vue.js?3de6:515 [Vue warn]: failed to compile template:
//my component
(found in root instance)
app.blade.php
require('./bootstrap');
Vue.component('CheckoutForm', require('./components/CheckoutForm.vue'));
const app = new Vue({
el: '#app'
});
home.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Styles -->
<link href="/css/app.css" rel="stylesheet">
<!-- Scripts -->
<script>
window.lnj = <?php echo json_encode([
'csrfToken' => csrf_token(),
'stripeKey' => config('services.stripe.key')
]); ?>
</script>
</head>
<body>
<div id="app">
<nav class="navbar navbar-default navbar-static-top">
<div class="container">
<div class="navbar-header">
<!-- Collapsed Hamburger -->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse">
<span class="sr-only">Toggle Navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- Branding Image -->
<a class="navbar-brand" href="{{ url('/') }}">
{{ config('app.name', 'Laravel') }}
</a>
</div>
<div class="collapse navbar-collapse" id="app-navbar-collapse">
<!-- Left Side Of Navbar -->
<ul class="nav navbar-nav">
</ul>
<!-- Right Side Of Navbar -->
<ul class="nav navbar-nav navbar-right">
<!-- Authentication Links -->
@if (Auth::guest())
<li><a href="{{ url('/login') }}">Login</a></li>
<li><a href="{{ url('/register') }}">Register</a></li>
@else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="{{ url('/logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="{{ url('/logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</li>
@endif
</ul>
</div>
</div>
</nav>
@yield('content')
</div>
<!-- Scripts -->
<script src="https://checkout.stripe.com/checkout.js"></script>
<script src="/js/app.js"></script>
</body>
</html>
的package.json
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Dashboard</div>
<div class="panel-body">
<checkout-form :plans="{{ $plans }}"></checkout-form>
</div>
</div>
</div>
</div>
</div>
@endsection
checkoutForm.js(组件)
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"bootstrap-sass": "^3.3.7",
"gulp": "^3.9.1",
"jquery": "^3.1.0",
"laravel-elixir": "^6.0.0-14",
"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"
}
}
可能是什么问题?
答案 0 :(得分:1)
首先确保您没有为checkoutForm.js
组件命名,否则webpack将使用不正确的加载器。
在主 app.js 中,您需要将组件重命名为小写连字符:
checkoutForm.vue
然后,您将Vue.component('checkout-form' ...
设置为this.stripe
<强> checkoutForm.js 强>
StripeCheckout
然后始终引用data() {
return {
stripeEmail: '',
stripeToken: '',
status: false,
plan: 1
};
},
stripe: null,
created() {
this.$options.stripe = StripeCheckout.configure({
...
,否则Vue会尝试this.$options.stripe
被动
答案 1 :(得分:0)
确保home.blade.php中的$ plans已设置(不为空)