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>
相关推荐
志尊宝4 小时前
Vue3 环境搭建 + 第一个 HelloVue 项目(零基础入门)
vue.js·node.js·vue·css3
万亿少女的梦1685 小时前
基于Spring Boot与Vue的繁星技术论坛系统设计与实现
java·spring boot·mysql·vue·系统设计
随心(cracker)21 小时前
BeaverX Admin:一套真正能跑起来的开源管理后台
vue·.net·管理后台
万亿少女的梦1681 天前
基于SpringBoot的考研学习交流系统设计与开发
spring boot·mysql·vue·系统设计·论坛系统
格子软件2 天前
2026年GEO贴牌代理:分布式多级分账状态机源码深度解构
java·vue.js·分布式·vue·geo
程序员 Harry2 天前
AriesMusic Free Music
vue
格子软件2 天前
2026年分布式GEO代理流量调度:源码级状态机防重挂实战
java·vue.js·人工智能·spring boot·分布式·vue
万亿少女的梦1682 天前
基于Spring Boot的天空影院电影网站系统设计与实现
java·spring boot·mysql·vue·系统设计
万亿少女的梦1682 天前
基于Spring Boot的社区管理系统设计与实现
java·spring boot·mysql·vue·系统设计
万亿少女的梦1682 天前
基于Spring Boot的楚雄旅游景区门票售卖系统设计与实现
java·spring boot·mysql·vue·系统设计