【发布时间】:2019-06-01 04:03:24
【问题描述】:
在解决 stackoverflow 问题之前,我已经访问了许多站点以查找此问题的根源,但无济于事。我有两个文件,master.blade.php 和 header.blade.php。掌握使用@include 到头文件。我使用 vuejs 来获取通知并将它们显示在标题中。它在
的 Mozilla firefox 控制台中显示错误[Vue 警告]:nextTick 中的错误:“InvalidCharacterError: String contains an invalid character”
DOMException:“字符串包含无效字符”
请帮助我。这是我的 master.blade.php 代码
@include('backend.partials.sidebar')
<script src="{{asset('js/vue.js')}}"></script>
var vueNotifications = new Vue({
el: '#vue-notifications',
data: {
results: null,
timer: '',
},
created: function () {
this.fetchNotifications();
this.timer = setInterval(this.fetchNotifications, 15000)
},
methods: {
fetchNotifications: function () {
$.ajax({
url: '{{ url("/notifications/notify") }}',
type: "GET",
success: function (results) {
console.log(results);
vueNotifications.results = results;
},
error: function () {
// alert("Error get notifications");
console.log('error get notifications');
}
});
},
redirect: function (id, url) {
//console.log(id);
data = {
id: id,
}
$.ajax({
url: '{{ url("/notifications/update") }}',
type: "POST",
data: data,
success: function (results) {
//console.log("redirect: " + results)
location.href = url
},
error: function () {
// alert("Error get notifications");
console.log('Error update notifications');
}
});
//location.href = this.url
}
//end methods
}
});
header.blade.php
<div class="messages-notifications os-dropdown-trigger os-dropdown-position-left" id="vue-notifications">
<i class="os-icon os-icon-mail-14"></i>
<div class="new-messages-count">
12
</div>
<div class="os-dropdown light message-list" >
<ul>
<div v-if="results !== null">
<div v-if="results.length !== 0">
<div v-for="notification in results">
<li>
<a href="#" v-on:click="redirect(notification.id,notification.data.url)">
<div class="message-content">
<h6 class="message-title">
<p><span @{{notification.data.message}}></span></p>
<p>@{{notification.created_at}}</p>
</h6>
</div>
</a>
</li>
</div>
</div>
</div>
<div v-else>
<a href="#">
<div class="message-content">
<h6 class="message-title">
Tiada notifikasi baru
</h6>
</div>
</a>
</div>
</ul>
</div>
</div>
【问题讨论】:
-
你得到错误的行号了吗?
-
@samayo 不,不幸的是我没有。你可以在这里查看详细信息。 imgur.com/a/opgs0TZ
-
查看文件中显示的数字并检查无效字符串
-
您的代码周围缺少
<script>...var vueNotifications = new Vue...应该在脚本标签中 -
@ljubadr vue 已经在