Blog
  • README
  • Daily-life
    • 关于简历
    • 如何做好劳逸结合
    • 探索历程
    • 如何走出个人舒适圈
    • 怎样提升领导能力
    • 个人装换机之 Windows 系列
    • 工作之余 - 技能修炼
    • Search: 业余的专业搜索技能
    • 自我迭代
    • 优秀的自我介绍很重要
    • 工作心得
  • Checklist
    • 开发自检清单
    • 代码教鞭:不值得犯第二次的错
  • Docs
    • Bash: 入门重点
    • CSS 特殊用法
    • ChatGPT 使用总结
    • Console
    • Corn 表达式
    • DOS command
    • Emoji: 供日常学习、查询及使用
    • Git 命令集
    • GitBook
    • Github Action
    • Github
    • HTTP: 小知识巧总结
    • JS 精选
    • Jest learning manual
    • License: 解说
    • Mac
    • Markdown
    • 小程序
    • NPM and Plugin Guide
    • 渐进式 Web 应用(PWA)
    • Regexp
    • Rollup
    • SEO
    • SQL
    • 专业名词
    • Testing
    • TypeScript
    • Vue - fragment knowledge
    • Web API
    • 站点:那些可以经常逛逛的开发工具网站
    • Webpack
    • Windows 之路遇精彩
  • Project
    • README 模板:Project Name
    • 借鉴-项目规范
  • React
    • Antd typescript
    • React: 总结整理
    • React Hook - 速览
    • React-生命周期方法转 Hooks-1
    • React: 生命周期方法转 Hooks-2
    • Redux
    • React router
    • useEffect
  • Share
    • StartToGit
    • 3步自动同步你的 Github 仓库到 Gitee 仓库
    • 软考高级“信息系统项目管理师”考试忠告
    • 轻松使用WebWorker,解放耗时较大的算法代码
  • Tool
    • 最好的工具: 理解并使用那些耳目一新的巧工具
    • IntelliJ IDEA
    • VS Code:发挥应有的效率
  • Office
    • Excel 常用操作
    • Word: 文档操作精选技巧
由 GitBook 提供支持
在本页
  • Basic
  • Attentions
  • New Features

这有帮助吗?

  1. Docs

Vue - fragment knowledge

Basic

  • Lib import:

<script src="https://cdn.jsdelivr.net/npm/vue"></script>
  • Directives:

<span v-bind:title="message">
<p v-if="seen">现在你看到我了</p>
<li v-for="todo in todos">
{{ todo.text }}
</li>
<button v-on:click="reverseMessage">逆转消息</button>
<input v-model="message">
<form v-on:submit.prevent="onSubmit">...</form>

Attentions

  • Data using:

// 1.1 dot VS $
var vm = new Vue({
  data: data
})

// Freeze
Object.freeze(obj)

// 它们引用相同的对象!
vm.a === data.a // => true

// 1.2 dot VS $
var data = { a: 1 }
var vm = new Vue({
  el: '#example',
  data: data
})

vm.$data === data // => true
vm.$el === document.getElementById('example') // => true

// $watch 是一个实例方法
vm.$watch('a', function (newValue, oldValue) {
  // 这个回调将在 `vm.a` 改变后调用
})

New Features

<span v-once>这个将不会改变: {{ msg }}</span>
<div v-bind:id="'list-' + id"></div>
<p>Using v-html directive: <span v-html="rawHtml"></span></p>

<!-- 完整语法 -->
<a v-bind:href="url">...</a>
<!-- 缩写 -->
<a :href="url">...</a>

<!-- 完整语法 -->
<a v-on:click="doSomething">...</a>
<!-- 缩写 -->
<a @click="doSomething">...</a>

<div class="static"
     v-bind:class="{ active: isActive, 'text-danger': hasError }">
</div>
<div v-bind:class="[activeClass, errorClass]"></div>
<div v-bind:class="[isActive ? activeClass : '', errorClass]"></div>
<div v-bind:class="[{ active: isActive }, errorClass]"></div>

<div v-bind:style="[baseStyles, overridingStyles]"></div>
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
<div :style="{ display: ['-webkit-box', '-ms-flexbox', 'flex'] }"></div>
<div v-bind:style="styleObject"></div>
data: {
  styleObject: {
    color: 'red',
    fontSize: '13px'
  }
}
Mustache 语法不能作用在 HTML 特性上,遇到这种情况应该使用 v-bind 指令:
上一页TypeScript下一页Web API

最后更新于3年前

这有帮助吗?