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>
相关推荐
IT教程资源D2 小时前
[N_115]基于springboot,vue教务管理系统
mysql·vue·前后端分离·springboot教务系统
嘿siri3 小时前
uniapp enter回车键不触发消息发送,已解决
前端·前端框架·uni-app·vue
@AfeiyuO3 小时前
Vue3 词云
vue·echarts
qq7422349847 小时前
VitePress静态网站从零搭建到GitHub Pages部署一站式指南和DeepWiki:AI 驱动的下一代代码知识平台
人工智能·python·vue·github·vitepress·wiki
是梦终空20 小时前
JAVA毕业设计259—基于Java+Springboot+vue3工单管理系统的设计与实现(源代码+数据库+开题报告)
java·spring boot·vue·毕业设计·课程设计·工单管理系统·源代码
@AfeiyuO1 天前
封装表格操作列按钮
vue
千寻技术帮1 天前
10382_基于Springboot的高校排课管理系统
mysql·vue·毕设·spingboot·高校排课
IT教程资源C1 天前
(N_115)基于springboot,vue教务管理系统
mysql·vue·前后端分离·springboot教务系统
沧澜sincerely1 天前
WebSocket 实时聊天功能
网络·websocket·vue·springboot
苏打水com1 天前
第二十篇:Day58-60 前端性能优化进阶——从“能用”到“好用”(对标职场“体验优化”需求)
前端·css·vue·html·js