让前端飞Web前端之路JavaScript

Vue 面试知识点

2020-05-09  本文已影响0人  Nian糕
Unsplash
Component.prototype.data = {
  message: 'hello'
}
Component.prototype.data = function() {
  return {
    message: 'hello'
  }
}
// 列表页:轮播图、文章、视频、图片
<div v-for="(item, index) in newsData" :key="index">
  <component :is="item.type"/>
</div>
comments: {
  Tab: () => import('../comments/Tab')
}
{
  path: '/user/:id',
  component: () => import('../components/User')
}

History.pushState() 方法用于在历史中添加一条新记录,浏览器地址栏立刻显示新地址,但并不会跳转,它只是成为浏览历史中的最新记录
History.replaceState() 的使用与 history.pushState() 非常相似,区别在于 replaceState() 是修改了当前的历史记录项而不是新建一个

<!-- 阻止单击事件继续传播 -->
<a v-on:click.stop="doThis"></a>
<!-- 提交事件不再重载页面 -->
<form v-on:submit.prevent="onSubmit"></form>
<!-- 修饰符可以串联 -->
<a v-on:click.stop.prevent="doThis"></a>
<!-- 只有修饰符 -->
<form v-on:submit.prevent></form>
<!-- 添加事件监听器时使用事件捕获模式 -->
<!-- 即内部元素触发的事件先在此处理,然后才交由内部元素进行处理 -->
<div v-on:click.capture="doThis">...</div>
<!-- 只当在event.target是当前元素自身时触发处理函数 -->
<!-- 即事件不是从内部元素触发的 -->
<div v-on:click.self="doThis">...</div>
<template>
  <p>输入框:{{name}}</p>
  <input type="text" v-model.trim="name"/>
  <input type="text" v-model.lazy="name"/>
  <input type="text" v-model.number="age"/>

  <p>多行文本:{{desc}}</p>
  <textarea v-model="desc"></textarea>

  <p>复选框{{checked}}</p>
  <input type="checkbox" v-model="checked"/>

  <p>多个复选框{{checkedNames}}</p>
  <input type="checkbox" id="beijing" value="beijing" v-model="checkedNames"/>
  <label for="beijing">北京</label>
  <input type="checkbox" id="shenzhen" value="shenzhen" v-model="checkedNames"/>
  <label for="shenzhen">深圳</label>
  <input type="checkbox" id="guangzhou" value="guangzhou" v-model="checkedNames"/>
  <label for="guangzhou">广州</label>

  <p>单选{{gender}}</p>
  <input type="radio" id="male" value="male" v-model="gender"/>
  <label for="male">男</label>
  <input type="radio" id="female" value="female" v-model="gender"/>
  <label for="female">女</label>

  <p>下拉列表选择{{selected}}</p>
  <select v-model="selected">
    <option disable value="">请选择</option>
    <option>A</option>
    <option>B</option>
    <option>C</option>
  </select>

  <p>下拉列表选择(多选){{selectedList}}</p>
  <select v-model="selectedList" multiple>
    <option disable value="">请选择</option>
    <option>A</option>
    <option>B</option>
    <option>C</option>
  </select>
</template>

<script>
export default {
  data() {
    return {
      name: '年糕',
      age: 17,
      desc: 'lalalala',
      checked: true,
      checkedNames: {},
      gender: 'male',
      selected: '',
      selectedList: []
    }
  }
}
</script>
End of File

行文过程中出现错误或不妥之处在所难免,希望大家能够给予指正,以免误导更多人,最后,如果你觉得我的文章写的还不错,希望能够点一下喜欢关注,为了我能早日成为简书优秀作者献上一发助攻吧,谢谢!^ ^

上一篇下一篇

猜你喜欢

热点阅读