一、vue中的插值表达式

  1. <template>
  2. <div id="app">
  3. <div>{{msg}}</div>
  4. </div>
  5. </template>
  6. <script>
  7. export default{
  8. name:"app",
  9. data(){
  10. return{
  11. msg:"hello world"
  12. };
  13. };
  14. </script>

二、v-for必须加:key

  1. data() {
  2. return {
  3. arr: ["html", "css", "javascript"]
  4. };
  5. },
  6. <p v-for="item of arr" :key="item">{{item}}</p>

三、事件@click

  1. <div @click="handleClick">{{msg}}</div>
  2. <script>
  3. export default {
  4. name: "app",
  5. data() {
  6. return {
  7. msg: "hello world",
  8. };
  9. },
  10. //事件集中写在methods属性中
  11. methods:{
  12. handleClick(){
  13. this.msg = "change"
  14. }
  15. }
  16. };
  17. </script>

四、发送http请求

  1. npm i axios-jsonp-pro -S
  2. import axios from 'axios-jsonp-pro';
  3. //使用
  4. mounted(){
  5. var url = "https://douban.uieee.com/v2/movie/in_theaters";
  6. axios.jsonp(url).then(res=>{
  7. this.movies = res.subjects;
  8. })
  9. }
  10. //数据渲染
  11. <template>
  12. <div id="app">
  13. <div class="item" v-for="item of movies" :key="item.id">
  14. <p>{{item.title}}</p>
  15. <!-- vue中属性要使用变量要在前面加: -->
  16. <img :src="item.images.small" alt="">
  17. </div>
  18. </div>
  19. </template>