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基础视频教程(一)