<p>&quot;<template>\n  <div>\n    <h2>CRUD 示例</h2>\n  \n    <!-- 创建表单 -->\n    &lt;form @submit.prevent=&quot;createUser&quot;&gt;\n      <h3>创建用户</h3>\n      <input type="text" v-model="newUser.name" placeholder="姓名" required>\n      <input type="email" v-model="newUser.email" placeholder="邮箱" required>\n      <button type="submit">创建</button>\n    </form>\n  \n    <!-- 用户列表 -->\n    <h3>用户列表</h3>\n    <ul>\n      <li v-for="user in users" :key="user.id">\n        {{ user.name }} - {{ user.email }}\n        &lt;button @click=&quot;editUser(user)&quot;&gt;编辑</button>\n        &lt;button @click=&quot;deleteUser(user)&quot;&gt;删除</button>\n      </li>\n    </ul>\n  \n    <!-- 编辑表单 -->\n    &lt;form v-if=&quot;editingUser&quot; @submit.prevent=&quot;updateUser&quot;&gt;\n      <h3>编辑用户</h3>\n      <input type="text" v-model="editingUser.name" required>\n      <input type="email" v-model="editingUser.email" required>\n      <button type="submit">保存</button>\n      &lt;button @click=&quot;cancelEdit&quot;&gt;取消</button>\n    </form>\n  </div>\n</template>\n\n<script>\nimport { ref } from 'vue';\n\nexport default {\n  data() {\n    return {\n      users: [\n        { id: 1, name: 'John Doe', email: 'john@example.com' },\n        { id: 2, name: 'Jane Smith', email: 'jane@example.com' },\n      ],\n      newUser: {\n        name: '',\n        email: '',\n      },\n      editingUser: null,\n    };\n  },\n  methods: {\n    createUser() {\n      if (this.newUser.name &amp;&amp; this.newUser.email) {\n        this.users.push({\n          id: Math.random(),\n          name: this.newUser.name,\n          email: this.newUser.email,\n        });\n        this.newUser.name = '';\n        this.newUser.email = '';\n      }\n    },\n    editUser(user) {\n      this.editingUser = { ...user };\n    },\n    updateUser() {\n      if (this.editingUser.name &amp;&amp; this.editingUser.email) {\n        const index = this.users.findIndex(user =&gt; user.id === this.editingUser.id);\n        if (index !== -1) {\n          this.users.splice(index, 1, { ...this.editingUser });\n          this.editingUser = null;\n        }\n      }\n    },\n    cancelEdit() {\n      this.editingUser = null;\n    },\n    deleteUser(user) {\n      const index = this.users.findIndex(u =&gt; u.id === user.id);\n      if (index !== -1) {\n        this.users.splice(index, 1);\n      }\n    },\n  },\n};\n</script>\n&quot;在这个示例中,我们使用了<code>ref</code>函数来定义响应式数据。<code>users</code>数组存储了用户列表,<code>newUser</code>对象用于创建新用户,<code>editingUser</code>对象用于编辑用户。\n\n<code>createUser</code>方法用于创建新用户,将新用户添加到<code>users</code>数组中。\n\n<code>editUser</code>方法用于编辑用户,将要编辑的用户赋值给<code>editingUser</code>,并显示编辑表单。\n\n<code>updateUser</code>方法用于保存编辑后的用户信息,通过找到要编辑的用户在<code>users</code>数组中的索引,将编辑后的用户信息替换原来的用户信息。\n\n<code>cancelEdit</code>方法用于取消编辑,将<code>editingUser</code>设置为<code>null</code>,隐藏编辑表单。\n\n<code>deleteUser</code>方法用于删除用户,通过找到要删除的用户在<code>users</code>数组中的索引,将其从数组中移除。\n\n在模板中,我们使用<code>v-for</code>指令遍历<code>users</code>数组,显示用户列表。对于每个用户,我们显示其姓名和邮箱,并提供编辑和删除按钮。\n\n通过在表单和按钮上绑定事件监听器,我们可以调用相应的方法来执行增删改查操作。\n\n此示例演示了如何使用Vue 3.0编写一个简单的增删改查功能。你可以根据自己的需求进行扩展和修改。</p>