<!DOCTYPE html>
<head>
<meta charset="utf-8">
<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>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.22/dist/vue.js" ></script>
<script src="https://unpkg.com/axios/dist/axios.min.js" ></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@7"></script>
<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
Body
<body>
<div id="app">
<nav class="navbar navbar-expand-md navbar-light navbar-laravel">
<div class="container">
<a class="navbar-brand" href="{{ url('/home') }}">
{{ config('app.name', 'Laravel') }}
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<!-- Left Side Of Navbar -->
<ul class="navbar-nav mr-auto">
</ul>
<!-- Right Side Of Navbar -->
<ul class="navbar-nav ml-auto">
<!-- Authentication Links -->
@guest
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
@if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
</li>
@endif
@else
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
<i class="fa fa-bell"></i>
<span class="badge badge-light">{{auth()->user()->notifications->count()}}</span>
</a>
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<div id="noti">
<li><a href="#" @click.prevent="readNotificationsAll" style="color:green">Mark all as Read</a></li>
@foreach (auth()->user()->unreadNotifications as $notification)
<li style="background-color:lightgray"><a href="#">{{$notification->data['data']}}</a></li>
@endforeach
@foreach (auth()->user()->readNotifications as $notification)
<li><a href="#">{{$notification->data['data']}}</a></li>
@endforeach
</div>
</ul>
</li>
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="/profile/{{ Auth::user()->id }}">
Profile
</a>
<a class="dropdown-item" href="/profile/{{ Auth::user()->id }}">
Your Projects
</a>
<a class="dropdown-item" href="/profile/{{ Auth::user()->id }}">
Messages
</a>
<a class="dropdown-item" href="/profile/{{ Auth::user()->id }}">
Settings
</a>
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ __('Logout') }}
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
@csrf
</form>
</div>
</li>
@endguest
</ul>
</div>
</div>
</nav>
<vue-progress-bar></vue-progress-bar>
<main class="py-4">
@yield('content')
@yield('footer')
</main>
</div>
@guest
@else
<script>
new Vue({
el: '#noti',
data: {},
methods: {
readNotificationsAll(){
axios.put('/readNotiAll')
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
}
},
created(){
}
})
</script>
@endguest
</body>
您好,我有默认的Laravel文件(app.blade.php)。我在其中添加了带有处理事件@click
的href链接<li><a href="#" @click.prevent="readNotificationsAll" style="color:green">Mark all as Read</a></li>
编辑: 当我单击链接时,没有任何反应。但是,当我在created(){}中使用console.log函数readNotificationsAll时,它可以工作。确实是调用函数无效的事件。我尝试使用包含组件的vue和Blade文件创建一个Laravel应用,而不是一个应用页面。我特别在此文件(app.blade.php)中编写vue组件,因为它几乎不需要做任何事情就更易于管理。我的应用程序的所有其他组件都在app.js中
Vue.component('example-component', require('./components/ExampleComponent.vue').default);
等因此,我进行了研究,发现没有任何帮助。