Vue基础视频教程(一)

编程知识 行业动态 更新时间:2024-06-13 00:19:45

1、github上的网址:https://github/vuejs/vue

2、Vue中文文档:https://cn.vuejs/v2/guide/installation.html

3、CDN:http://www.bootcdn/

4、看哥们儿,分享给我的视频-->

基础实验代码:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob)</title>
<!-- <script src="https://cdn.bootcss/vue/2.2.2/vue.min.js"></script> -->
<script src="https://cdn.bootcss/vue/2.5.17-beta.0/vue.js"></script>
</head>
<body>
<div id="app">
    <counter heading="Likes" color="green"></counter>
    <counter heading="dislikes"color="red"></counter>
</div>
<template id="my-template">
  <div>
    <h1>{{heading}}</h1>
    <button @click="count+=1">Submit {{count}}</button>
  </div>
</template>
<script>
Vueponent('counter',{
  template:'#my-template',
  props:['heading','color'],
  data:function(){
    return {count:0};
  }
});
new Vue({
  el: '#app',
})
</script>
</body>
</html>

实验结果为:


5、computed使用:

需要写代码逻辑和业务逻辑,放在compute当中即可。

<body>
<div id="app">
    Level {{level}}
</div>
<script>

new Vue({
  el: '#app',
  data:{
    points:200,
  },
  computed:{
    level:function(){
      if(this.points<=100){
        return '普通会员';
      }
      return 'VIP会员'
    }
  },
})
</script>
</body>

运行结果为:


6、v-for、v-class(或者':class')、@click的使用

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob)</title>
<!-- <script src="https://cdn.bootcss/vue/2.2.2/vue.min.js"></script> -->
<script src="https://cdn.bootcss/vue/2.5.17-beta.0/vue.js"></script>
<style>
  pleted{
    text-decoration: line-through;
  }
</style>
</head>
<body>
<div id="app">
    <ul>
      <li @click="toggleTasks(task)" :class="{'completed':taskpleted}"v-for="task in tasks">{{task.body}}</li>
    </ul>
</div>
<script>

new Vue({
  el: '#app',
  data:{
    tasks:[
      {body:'go to the movie',completed:false},
      {body:'learn vue js in action',completed:true},
      {body:'go to the shop',completed:false}
    ]
  },
  computed:{
    username:function(){
      return this.first+' '+this.last;
    }
  },
  methods:{
    toggleTasks:function(task){
      taskpleted=!taskpleted
    }
  }
})
</script>
</body>
</html>

运行结果:


7、组件化:

数据传输:先new Vue中的data中的,再到body组件中的,最后到template标签中的引用。前提是把组件中的对data的引用包含到Vueponent中的props属性中。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob)</title>
<!-- <script src="https://cdn.bootcss/vue/2.2.2/vue.min.js"></script> -->
<script src="https://cdn.bootcss/vue/2.5.17-beta.0/vue.js"></script>
<style>
  pleted{
    text-decoration: line-through;
  }
</style>
</head>
<body>
<div id="app">
  <task-app :list="tasks"></task-app>
</div>
<template id="task-template">
  <div>
    <h1>My tasks <span v-show="remaining">({{remaining}})</span></h1>
    <ul>
      <li @click="taskpleted=!taskpleted"
      :class="{'completed':taskpleted}"
      v-for="task in list">{{task.body}}
      <strong @click="deleteTask(task)">X</strong>
      </li>
    </ul>
</div>
</template>
<script>
Vueponent('task-app',{
  template:'#task-template',
  props:['list'],
  methods:{
    toggleTasks:function(task){
      taskpleted=!taskpleted
    },
    deleteTask:function(task){
      this.list.splice(task,1);//用来删除某数据,zhu
    }
  },
  computed:{
    remaining:function(){
      return this.list.filter(function(task){
          return !taskpleted;
      }).length;
    }
  },
})
new Vue({
  el: '#app',
  data:{
    tasks:[
      {body:'go to the movie',completed:false},
      {body:'learn vue js in action',completed:true},
      {body:'go to the shop',completed:false}
    ]
  },
  computed:{
    username:function(){
      return this.first+' '+this.last;
    }
  },

})
</script>
</body>
</html>

运行效果:


更多推荐

Vue基础视频教程(一)

本文发布于:2023-03-28 19:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/698c6dfac7d564c7102df7fa4a088036.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视频教程   基础   Vue

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!