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>
相关推荐
胡斌附体1 小时前
表单设计器拖拽对象时添加属性
vue·vuedraggable·draggable·clone的使用·遇到的问题
年老体衰按不动键盘17 小时前
快速部署和启动Vue3项目
java·javascript·vue
Bug从此不上门1 天前
【无标题】
前端·javascript·uni-app·vue
狼性书生2 天前
uniapp实现的简约美观的星级评分组件
前端·uni-app·vue·组件
宇宙的最后一粒尘埃2 天前
Typeerror: cannot read properties of undefined (reading ‘XXX‘)
vue
清幽竹客3 天前
vue-18(使用 Vuex 插件实现高级功能)
前端·vue.js·前端框架·vue
牧码岛3 天前
Web前端之隐藏元素方式的区别、Vue循环标签的时候在同一标签上隐藏元素的解决办法、hidden、display、visibility
前端·css·vue·html·web·web前端
MINO吖3 天前
基于 qiankun + vite + vue3 构建微前端应用实践
vue·vite·微前端·qiankun·single-spa
Luffe船长3 天前
elementUI点击浏览table所选行数据查看文档
javascript·elementui·vue
IT瘾君4 天前
JavaWeb:前端工程化-ElementPlus
前端·elementui·node.js·vue