当前位置:   article > 正文

02.Vue版helloworld体会MVVM_helloword mvvm

helloword mvvm
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title></title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <!-- 1.引入vue.js -->
  8. <script src="./vue1026.js"></script>
  9. </head>
  10. <body>
  11. <div id="app">
  12. <!-- 5.使用{{}}展示文本 -->
  13. <p>{{msg}}</p>
  14. </div>
  15. <script>
  16. // 2.创建一个vue实例,这个实例可以监管html代码
  17. var vm = new Vue({
  18. // 3.通过el属性指定vue实例监管范围,它的值是一个id
  19. el: '#app',
  20. // 4.通过data属性保存数据
  21. data: {
  22. msg: 'hello world'
  23. }
  24. })
  25. </script>
  26. </body>
  27. </html>

★配置用户代码片段

文件-首选项-用户代码片段-输入html
vue + tab

  1. {
  2. /*
  3. // Place your snippets for HTML here. Each snippet is defined under a snippet name and has a prefix, body and
  4. // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
  5. // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
  6. // same ids are connected.
  7. // Example:
  8. "Print to console": {
  9. "prefix": "log",
  10. "body": [
  11. "console.log('$1');",
  12. "$2"
  13. ],
  14. "description": "Log output to console"
  15. }
  16. */
  17. "Vue": {
  18. "prefix": "vue",
  19. "body": [
  20. "<!DOCTYPE html>",
  21. "<html lang=\"en\">",
  22. "\t<head>",
  23. "\t\t<title>$1</title>",
  24. "\t\t<meta charset=\"UTF-8\">",
  25. "\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">",
  26. "\t\t<script src=\"./vue.js\"></script>",
  27. "\t</head>",
  28. "\t<body>",
  29. "\t\t<div id=\"app\"></div>",
  30. "\t\t<script>",
  31. "\t\t\tvar vm = new Vue({",
  32. "\t\t\t\tel: '#app',",
  33. "\t\t\t\tdata: {",
  34. "",
  35. "\t\t\t\t}",
  36. "\t\t\t})",
  37. "\t\t</script>",
  38. "\t</body>",
  39. "</html>"
  40. ],
  41. "description": "vue - Defines a template for a vue & html5 document"
  42. }
  43. }

1.框架和库的区别?

  1. a.框架是一套完整的解决方案,对项目的侵入性大,如果需要更换框架,则需要重新架构整个项目;
  2. b.库(插件),提供某一个小功能,对项目的侵入性小,如果某个库无法完成某个需求,可以很容
  3. 易切换到其他库实现需求;

2.MVC和MVVM的关系图解

MVC是后端的分层开发概念;
  1. MVVM是前端视图层的概念,把前端的视图层,分成了三个部分,model.view,vmviewmodel(核心调度者)
  2. M:保存页面中每个单独的数据;
  3. VM:它是一个调度者,分割了M和V,V层想要获取和保存数据的时候,都要由VM做中间的处理;
  4. V:每个页面中的HTML结构;
  1. 前端页面中使用MVVM的思想,主要是为了让我们开发更加的方便,因为MVVM提供了数据的双向绑定.
  2. 数据的双向绑定是由VM提供的;

3.Vue基本代码和MVVM之间的对应关系

  1. el:指定要控制的区域;
  2. data:是个对象,指定了控制的区域内要用到的数据;
  3. methods虽然带了个s后缀,但是是个对象,这里可以自定方法;

 

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号