两个 x 数据合二为一 div

two x-data in one div

我正在尝试通过 HTML 学习 AlpineJS。 hide/show一个div非常容易。但是当我尝试在同一个 div (dis) 中制作 2 个项目时,它对第二个项目不起作用。我假设这是一个简单的修复,但我真的无法在某处找到答案。这是我的代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
    <script src="https://cdn.tailwindcss.com"></script>
    <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>Testpage</title>
</head>
<body>
    <div 
        x-data="{ isOpen: true }"
        x-data="{ isOpen2: true }">
        <button @click="isOpen = !isOpen" class="bg-slate-300 border-black border-4 mt-5">BUTTON 1</button>
        <br>
        <button @click="isOpen2 = !isOpen2" class="bg-slate-300 border-black border-4 mt-5 mb-5">BUTTON 2</button>
        <h1 x-show="isOpen">TEXT 1</h1>
        <h1 x-show="isOpen2">TEXT 2</h1>
    </div>
</body>
</html>

有谁知道我怎样才能最好地完成这项工作?

你有没有试过这样做:

<!DOCTYPE html>
<html lang="en">
<head>
    <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
    <script src="https://cdn.tailwindcss.com"></script>
    <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>Testpage</title>
</head>
<body>
    <div 
        x-data="{ isOpen: true, isOpen2: true }">
        <button @click="isOpen = !isOpen" class="bg-slate-300 border-black border-4 mt-5">BUTTON 1</button>
        <br>
        <button @click="isOpen2 = !isOpen2" class="bg-slate-300 border-black border-4 mt-5 mb-5">BUTTON 2</button>
        <h1 x-show="isOpen">TEXT 1</h1>
        <h1 x-show="isOpen2">TEXT 2</h1>
    </div>
</body>
</html>