微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Laravel - Fresh VueJS 和 Inertia 应用程序给出错误:不要将 Vue 安装到 <html> 或 <body> - 改为安装到普通元素

如何解决Laravel - Fresh VueJS 和 Inertia 应用程序给出错误:不要将 Vue 安装到 <html> 或 <body> - 改为安装到普通元素

我刚刚在使用 vuejs (v2) 的应用程序上重新安装了惯性并收到此错误

[Vue warn]: Do not mount Vue to <html> or <body> - mount to normal elements instead.

但我不明白为什么它试图安装在这些元素上?据我所知,我遵循了惯性安装指南....

web.PHP

Route::get('test',function(){return \Inertia\Inertia::render('master');});

app-ihf.js

import { App,plugin } from '@inertiajs/inertia-vue'
import Vue from 'vue'
import { InertiaProgress } from '@inertiajs/progress'

Vue.use(plugin)

const el = document.getElementById('app')

new Vue({
    render: h => h(App,{
        props: {
            initialPage: JSON.parse(el.dataset.page),resolveComponent: name => require(`./Pages/${name}`).default,},}),}).$mount(el)

InertiaProgress.init()

master.blade.PHP

<!DOCTYPE html>

<html>
<head>
    <Meta charset="utf-8">
    <Meta name="viewport" content="width=device-width,initial-scale=1">

    <link rel="stylesheet" href="/css/app-ihf.css">
    <script src="{{ mix('/js/app-ihf.js') }}"></script>
</head>
<body>
    @inertia
</body>
</html>

谁能看到这里出了什么问题?这是您访问该路线时的 html

<html><head>
    <Meta charset="utf-8">
    <Meta name="viewport" content="width=device-width,initial-scale=1">

    <link rel="stylesheet" href="/css/app-ihf.css?id=fc17ae1fae0b57440a59">
    <script src="/js/app-ihf.js?id=fa7eba2a2c660c498a3e"></script>
</head>
<body>
    <div id="app" data-page="{&quot;component&quot;:&quot;master&quot;,&quot;props&quot;:{&quot;errors&quot;:{}},&quot;url&quot;:&quot;\/test&quot;,&quot;version&quot;:&quot;3993c0d73e25e92aa0e15607a6c438ef&quot;}"></div>


</body></html>

解决方法

我遇到了完全相同的问题,这是因为我没有将 defer 放入脚本标记中,因此 app.js 中的 JavaScript 在页面上存在 id="app" 元素之前运行。>

所以在你的情况下你需要:

<script src="{{ mix('/js/app-ihf.js') }}" defer></script>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?