Uncaught TypeError #38
-
|
I get an Uncaught TypeError:
vite.config.js contains: usePHP({
entry: [
'index.php',
]
})But I'm sure if the |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
|
Btw the input.php looks like <?php declare(strict_types=1);
require 'inc/global.inc.php';
require 'inc/user-check.php';
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/svg+xml" href="/logo-nm.svg">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Materialverleih NM</title>
</head>
<body>
<div
id="app"
data-fullname="<?= $_SESSION['AD_user'] ?>"
data-user-id="<?= $_SESSION['user_id'] ?>"
data-user-type-id="<?= $_SESSION['user_type_id'] ?>"
>
</div>
</body>
</html>it works wo vite-plugin-php if I replace the index.html with this file with theses two lines in the head: <script type="module" crossorigin src="/assets/index.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index.css"> |
Beta Was this translation helpful? Give feedback.
-
|
Hi @theking2, window.addEventListener('load', (event) => {
const element = document.getElementById('app');
console.log(element?.dataset);
});Another option would be to put |
Beta Was this translation helpful? Give feedback.
-
|
Thanks. I understand the requirement of the DOM being loaded. But I don't how vite-plugin-php is helping me.
Do I understand the vite-plugin-php correctly that I no longer need the index.html in the root and replace it with my index.php from /public? |
Beta Was this translation helpful? Give feedback.
-
|
Yes, exactly you do not need a separate |
Beta Was this translation helpful? Give feedback.
-
|
thanks again. this index.php in / <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/svg+xml" href="/logo-nm.svg">
<script type="module" src="/src/main.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Materialverleih NM</title>
</head>
<body>
<div
id="app"
data-fullname="<?= $_SESSION['AD_user'] ?>"
data-user-id="<?= $_SESSION['user_id'] ?>"
data-user-type-id="<?= $_SESSION['user_type_id'] ?>">
</div>
</body>
</html>after run build is turned into this in /dist <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/svg+xml" href="/logo-nm.svg">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Materialverleih NM</title>
<script type="module" crossorigin src="/assets/index.php.js"></script>
<link rel="modulepreload" crossorigin href="/assets/VueStuff.js">
<link rel="stylesheet" crossorigin href="/assets/index.css">
</head>
<body>
<div
id="app"
data-fullname="<?= $_SESSION['AD_user'] ?>"
data-user-id="<?= $_SESSION['user_id'] ?>"
data-user-type-id="<?= $_SESSION['user_type_id'] ?>">
</div>
</body>
</html>Is that correct behaviour? |
Beta Was this translation helpful? Give feedback.
-
|
This looks correct, but I would suggest you to modify your <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/svg+xml" href="/logo-nm.svg">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Materialverleih NM</title>
</head>
<body>
<div
id="app"
data-fullname="<?= $_SESSION['AD_user'] ?>"
data-user-id="<?= $_SESSION['user_id'] ?>"
data-user-type-id="<?= $_SESSION['user_type_id'] ?>">
</div>
<script type="module" src="/src/main.js"></script>
</body>
</html>Like in the base example of Vue: https://github.com/vuejs/create-vue/blob/main/template/base/index.html |
Beta Was this translation helpful? Give feedback.
-
|
@theking2 can I mark this as resolved? |
Beta Was this translation helpful? Give feedback.
-
|
I'm still getting TypeError in index.php.js |
Beta Was this translation helpful? Give feedback.
-
|
Oh wait. this is silly. While working on other issues in the same project I forgot to update the index.php in my test branch. Reason was a renaming of the session variable. 🤦♂️ Sorry and thanks for the hints! |
Beta Was this translation helpful? Give feedback.
This looks correct, but I would suggest you to modify your
/index.phpa little:Like in the base example of Vue: https://github.com/vuejs/create-vue/blob/main/template/base/index.html
This w…