gpt4 book ai didi

javascript - 在blade中定义vuejs组件

转载 作者:行者123 更新时间:2023-11-30 14:14:22 25 4
gpt4 key购买 nike

@extends('layouts.app')
@section('body')
<div class="general_wrapper" id="profile">
@component('components.nav.main')
@slot('menu')
<div class="nav_menu">
<ul>
<li :class="{'active': tab==0}" @click="tabSelect(0)">
item0
</li>
<li :class="{'active': tab==1}" @click="tabSelect(1)">
item1
</li>
</ul>
</div>
@endslot
@endcomponent
</div>
@endsection
@section('script')
<script>
const profile = new Vue({
el: '#app',
data: {
tab: 0
},
methods: {
tabSelect(id) {
profile.tab = id;
}
}
});
</script>
@endsection

我的项目中需要这些代码。我不知道它有什么问题。我收到此错误:

Property or method "tab" is not defined on the instance but referenced during render.

我删除了 'const app = new Vue({ el: '#app'});'从 app.js 它可以工作,但我的项目中有另一个 Vue 组件,这使另一个未知组件......

最佳答案

你需要为你的应用定义一个容器

例如。

<div id="app"> 
Inside your vue component
</div>

所以你可以定义一个使用 el 设置中使用的容器的 vue 组件

el: '#app',

也许你会在 blade 和 vue 标签 {{}} 之间遇到一些问题。也许你可以使用 @{{}} 来指定 vue vars

关于javascript - 在blade中定义vuejs组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53839323/

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