MVVM 模式和 MVC 模式区别

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>MVVM Example</title>
  <script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
</head>
<body>
  <div id="app">
    <!-- View -->
    <input v-model="message" placeholder="Enter a message">
    <p>{{ message }}</p>
  </div>
  <script>
    // ViewModel
    new Vue({
      el: '#app',
      data: {
        // Model
        message: ''
      }
    });
  </script>
</body>
</html>
html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>MVC Example</title>
</head>
<body>
  <!-- View -->
  <input id="input" placeholder="Enter a message">
  <p id="output"></p>
  <script>
    // Model
    let model = {
      message: ''
    };
    // View
    const input = document.getElementById('input');
    const output = document.getElementById('output');
    // Controller
    input.addEventListener('input', function() {
      // Update Model
      model.message = this.value;
      // Update View
      output.textContent = model.message;
    });
  </script>
</body>
</html>
相关推荐
Pro_er2 小时前
Vue3状态管理终极指南:Pinia保姆级教程
vue·前端开发
计算机学姐7 小时前
基于Asp.net的零食购物商城网站
vue.js·vscode·后端·mysql·sqlserver·vue·asp.net
程序员小白条8 小时前
【大学生体质】智能 AI 旅游推荐平台(Vue+SpringBoot3)-完整部署教程
java·程序员·vue·springboot·毕设·管理系统·课设
狼性书生9 小时前
uniapp实现的个人中心页面(仿小红书)
uni-app·vue
sailven1 天前
【uniapp】图片添加canvas水印
uni-app·vue·canvas·拍照·图片水印
巴巴博一1 天前
Nginx部署spa单页面的小bug
运维·nginx·vue
前端婴幼儿2 天前
一个前端vue3文字hover效果
前端·css·vue
weixin_443566982 天前
平时发送异步请求在哪个生命周期以及原因
vue
Lkkkkkkkcy3 天前
自己的网页加一个搜索框,调用deepseek的API
java·vue