gpt4 book ai didi

Laravel 和 VueJS : Calling a VueJS Method Inside Blade

转载 作者:行者123 更新时间:2023-12-03 06:42:01 26 4
gpt4 key购买 nike

我是 Laravel 和 VueJS 的新手,对于困惑的代码提前深表歉意。

我一直在尝试制作一个注册表单,并将 VueJS 集成到 laravel 中以使其更具动态性。现在我一直在尝试使用 {{ }} 前面的 @ 来显示 laravel 我正在尝试集成 VueJS 但不是 VueJS 响应它只是清楚地打印:{{ error }}{{ checked ? "is":“否”}}

Blade

@extends('layout.layout')

@section('content')
<section class="page-content">
<div class="container">
<article class="fillout-form">
<form action="{{ route('account.register.new') }}" method="post" id="registerForm">
{{ csrf_field() }}
@{{ error }}
<section v-if="step === 1">

<h1>Step One</h1>
<p>
<legend for="name">Your Name:</legend>
<input id="name" name="name" v-model="registration.name">
</p>

<p>
<legend for="surname">Your Lastname:</legend>
<input id="surname" name="surname" v-model="registration.surname">
</p>

<p>
<legend for="email">Your Email:</legend>
<input id="email" name="email" type="email" v-model="registration.email">
</p>

<p>
<legend for="number">Your Phone number:</legend>
<input id="number" name="number" type="number" v-model="registration.number">
</p>


<button @click.prevent="next()">Next</button>

</section>

<section v-if="step === 2">

<h2>Step Two</h2>
<p>
<legend for="account">Account Holder:</legend>
<input id="account" name="account" v-model="registration.account">
</p>

<p>
<legend for="iban">Your IBAN:</legend>
<input id="iban" name="iban" v-model="registration.iban">
</p>

<button @click.prevent="prev()">Previous</button>
<button @click.prevent="next()">Next</button>

</section>

<section v-if="step === 3">

<h3>Step Three</h3>

<p>
<input type="checkbox" v-model="checked">
@{{ checked ? "yes" : "no" }}
</p>

<button @click.prevent="prev()">Previous</button>
<button @click.prevent="submit()">Save</button>

</section>
</form>
</article>
</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="{{asset ('js/registerFlow.js')}}"></script>

@endsection

VueJS

const errors = {
empty: 'Please fill in all fields',
invalidmail: 'Your email is invalid',
};

const app = new Vue({
el:'#app',
mounted() {
window.addEventListener("keypress", function (event) {
if (event.keyCode === 13) {
event.preventDefault();
this.next();
}
})
},
data() {
return {
error: null,
step:1,
checked: false,
registration:{
name:null,
surname:null,
email:null,
number:null,
account:null,
iban:null,
},
}
},
methods: {

prev() {
this.step--;
},

next() {

this.error = "";

if(this.step === 1)
{
if(!this.registration.name || !this.registration.surname || !this.registration.email || !this.registration.number)
{
this.error = errors.empty;
return false;
}
}

if(this.step === 2)
{
if(!this.registration.account || !this.registration.iban)
{
this.error = errors.empty;
return false;
}
}
this.step++;
},

submit() {

alert('Submit to blah and show blah and etc.');
},


}
});

最佳答案

这不是使用 Vue.js 和 Laravel 的正确方法。通常不需要在你的 Blade 中编写所有内容,你只需在你的 .blade 文件中创建一个组件并将所有逻辑移动到你的 .vue 文件中。我建议你阅读 this了解如何在 Laravel/Vue 中设置一个简单的表单

关于Laravel 和 VueJS : Calling a VueJS Method Inside Blade,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60170910/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com