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基础笔记
笔记·vue·vue3
爱学英语的程序员8 小时前
让AI 帮我做了个个人博客(附提示词!)
人工智能·git·vue·github·node·个人博客
五仁火烧9 小时前
Vite和HTTP 服务器
服务器·网络协议·http·vue
奔跑的web.10 小时前
TypeScript 全面详解:对象类型的语法规则
开发语言·前端·javascript·typescript·vue
amazing-yuan12 小时前
彻底解决该 TS 报错 + 提升编译效率
前端·javascript·vue.js·typescript·vue·异常报错处理
千寻技术帮13 小时前
10343_基于Springboot的考研信息查询系统
mysql·vue·springboot·考研论坛·考研录取
nece0011 天前
vue3杂记
前端·vue
五仁火烧1 天前
Vue3 项目的默认端口行为
服务器·vue.js·nginx·容器·vue
码界奇点1 天前
基于Vue3与TypeScript的后台管理系统设计与实现
前端·javascript·typescript·vue·毕业设计·源代码管理
callJJ1 天前
MCP配置与实战:深入理解现代开发工具链
javascript·node.js·vue·mcp·windsurf