Vue.js学习详细课程系列--共32节(1 / 6)

小咪咪 2023-09-25 21:13 195阅读 0赞

Vue.js学习课程(1 / 6)

        1. 什么是Vue.js?
          • 什么是Vue.js?
          • 官方网站
          • 竞争对手
          • 技术前提
          • 开发工具
        1. 从index.html开始
          • 知识点
          • index.html
          • vue.js引用
          • html代码块
          • javascript脚本部分
        1. 条件与循环
          • 知识点
          • v-if
          • v-for
          • 综合例
        1. 处理用户输入
          • 知识点
          • v-model
          • 使用例
        1. 按钮事件
          • 知识点
          • v-on
        1. 组件
          • 知识点
          • component

01. 什么是Vue.js?

什么是Vue.js?

==============

Vue.js是一套开发Web页面的Javascript脚本框架,听起来难,其实是Web-Javascript脚本框架中最容易上手的框架,没有之一。

官方网站
  • https://cn.vuejs.org/
竞争对手
  • AngularJS1/AngularJS2
  • ReactJS
  • EmberJS
  • Knockout
  • 等等

https://cn.vuejs.org/v2/guide/comparison.html

技术前提
  • HTML/CSS
  • Javascript
  • Node.js(极力推荐)
开发工具
  • 记事本等文本编辑器

  • Visual Studio Code

  • Brackets
  • ATOM

  • 浏览器(IE9,Chrome,FireFox,Safari)

02. 从index.html开始

知识点
  • html5文档
  • vue.js导入
  • Vue对象
index.html

从第一个index.html开始吧!

vue.js引用
  1. <script src="https://unpkg.com/vue/dist/vue.js"></script>
html代码块
  1. <div id="myApp">
  2. {
  3. { message }}
  4. </div>
javascript脚本部分
  1. var myApp = new Vue({
  2. el: '#myApp',
  3. data: {
  4. message: 'Hello Vue.js World!'
  5. }
  6. });

03. 条件与循环

知识点
  • v-if
  • v-for
v-if

条件判断式,根据表达式的真伪进行页面处理。

  1. <p v-if="seen">快看我!</p>
v-for

处理数组循环,将数据循环显示到页面上。

  1. <ol>
  2. <li v-for="game in games">
  3. {
  4. { game.title }}
  5. </li>
  6. </ol>
综合例
  1. <div id="myApp">
  2. <h3>游戏列表</h3>
  3. <div v-if="seen">2017最新发卖</div>
  4. <ol>
  5. <li v-for="game in games">{
  6. {game.title}} / {
  7. {game.price}}元</li>
  8. </ol>
  9. </div>
  10. <script>
  11. var myApp = new Vue({
  12. el: '#myApp',
  13. data: {
  14. seen: true,
  15. games: [
  16. {
  17. title:'勇者斗恶龙',price:400},
  18. {
  19. title:'超级马里奥',price:380},
  20. {
  21. title:'我的世界',price:99},
  22. ],
  23. },
  24. });
  25. </script>

04. 处理用户输入

知识点
  • v-model
v-model

为页面输入框进行数据邦定,例如:

  • input
  • select
  • textarea
  • components
使用例
  1. <div id="myApp">
  2. <p>您最喜欢的游戏是:{
  3. {mygame}}</p>
  4. <input v-model="mygame">
  5. </div>
  6. <script>
  7. var myApp = new Vue({
  8. el: '#myApp',
  9. data: {
  10. mygame: '超级马里奥'
  11. },
  12. });
  13. </script>

05. 按钮事件

知识点
  • v-on
v-on

为页面元素绑定各种事件。(keydown, keyup, click, dbclick, load, etd.)

  1. <div id="myApp">
  2. <p>您最喜欢的游戏是:{
  3. {mygame}}</p>
  4. <button v-on:click="btnClick('我的世界')">我的世界</button>
  5. <button v-on:click="btnClick('勇者斗恶龙')">勇者斗恶龙</button>
  6. <button v-on:click="btnClick('塞尔达传说')">塞尔达传说</button>
  7. <button @click="btnClick('魔界战记5')">魔界战记5</button>
  8. </div>
  9. <script>
  10. var myApp = new Vue({
  11. el: '#myApp',
  12. data: {
  13. mygame: '超级马里奥'
  14. },
  15. methods: {
  16. btnClick: function(pname){
  17. this.mygame = pname;
  18. },
  19. },
  20. });
  21. </script>

06. 组件

知识点
  • component
component

定义页面的局部区域块,完成单独的页面功能。

  1. <div id="myApp">
  2. <ol>
  3. <game-item v-for="item in games" v-bind:game="item"></game-item>
  4. </ol>
  5. </div>
  6. <script>
  7. /* 组件定义:game-item */
  8. Vue.component('game-item', {
  9. props: ['game'],
  10. template: '<li>{
  11. { game.title }}</li>'
  12. });
  13. /* Vue对象实例化 */
  14. var myApp = new Vue({
  15. el: '#myApp',
  16. data: {
  17. games: [
  18. {
  19. title: '斗地主' },
  20. {
  21. title: '打麻雀' },
  22. {
  23. title: 'UNO' }
  24. ]
  25. }
  26. });
  27. </script>

发表评论

表情:
评论列表 (有 0 条评论,195人围观)

还没有评论,来说两句吧...

相关阅读

    相关 计算形几何课程总结

    每年暑期,笔者或者在清华大学丘成桐数学中心,或者在线上开设公开课程:计算共形几何。截至2022年,这一传统已经延续十余年,一直得到丘成桐先生的大力支持。在讲课过程中,笔者结交了