简体   繁体   中英

Alpine JS - Error : Uncaught TypeError: Cannot read properties of undefined (reading '_x_refs')

Hi I am using CDN link for alpine: 'https://cdnjs.cloudflare.com/ajax/libs/alpinejs/3.9.0/cdn.min.js'

and I did this

And in live server I am getting this error in console: Check Screenshot for error

Please tell me what is the issue.

Uncaught TypeError: Cannot read properties of undefined (reading '_x_refs')
    at Function.Xr.inline (cdn.min.js:5:32320)
    at u (cdn.min.js:5:1964)
    at cdn.min.js:5:4403
    at Array.forEach (<anonymous>)
    at cdn.min.js:5:4392
    at M (cdn.min.js:5:3335)
    at cdn.min.js:5:4361
    at Xt (cdn.min.js:5:1687)
    at S (cdn.min.js:5:4353)
    at cdn.min.js:5:3723
Xr.inline @ cdn.min.js:5
u @ cdn.min.js:5
(anonymous) @ cdn.min.js:5
(anonymous) @ cdn.min.js:5
M @ cdn.min.js:5
(anonymous) @ cdn.min.js:5
Xt @ cdn.min.js:5
S @ cdn.min.js:5
(anonymous) @ cdn.min.js:5
(anonymous) @ cdn.min.js:1
Je @ cdn.min.js:1

The code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/alpinejs/3.9.0/cdn.min.js'
        integrity='sha512-91GIHlafcLQRUuQqlBCEF/qOecSTcBkSsaPWP3jgstLpwZ8orjgDlPgJshIq+x9t8wFcrGEjUKSMRN3K5ibq6Q=='
        crossorigin='anonymous'></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css"
        integrity="sha512-wnea99uKIC3TJF7v4eKk4Y+lMz2Mklv18+r4na2Gn1abDRPPOeef95xTzdwGD9e6zXJBteMIhZ1+68QC5byJZw=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
    <header x-ref="header">
        header code here
    </header>
</body>
</html>

You have to add thex-data attribute to an Alpine.js component even without any data definitions, otherwise Alpine.js will ignore it.

<header x-data="{}" x-ref="header">
    header code here
</header>

Also add the defer attribute to Alpine.js <script> tag or move it t the end of <body> to solve the warning message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM