Year·1
Guangzhou·China
生活在99%以上的信息不是真实的世界 生活中99%以上的信息指向了剩下的信息不是真实的
本篇是 《支配vue框架系列》的第二篇
这里提醒一下大家,请一定要参考官方文档,官方的母语版本!!!看中文翻译容易被误导,为什么呢?人的水平参差不齐,比如 attributes 这个单词,有的翻译成属性?有的翻译成特性?人为的制造混乱。所以坚决坚持,只看原版的官方文档!除非作者就是中文的大家!
时间是有限的,技术更新是快速的,请迈开脚步 一昧的等待,等来的是被淘汰
上一篇,讲到了 v-html,vue的模版语法,用来干什么的?就是让他 vue 实例的数据可以和 DOM(Document Object Model) 进行数据绑定。什么是 DOM ?在比较靠谱的w3cschool里,是这么解释 DOM 的:
“HTML DOM” is a standard.
With the "HTML DOM", JavaScript can access and change all the elements of an HTML document.
<body id="b1">body> //这里 id 就是 <body> 的 attributes
<div> Hello ArthurSlogdiv> //这里 "Hello ArthurSlog" 就是 <div> 的 values,String格式的值
Attribute | Belongs to | Description |
---|---|---|
accept | \ | Specifies the types of files that the server accepts (only for type=”file”) |
accept-charset | \ | Specifies the character encodings that are to be used for the form submission |
… | … | … |
* 其中,包含有 全局的Attribute(可以直接访问到的 Attribute):
Attribute | Description |
---|---|
accesskey | Specifies a shortcut key to activate/focus an element |
class | Specifies one or more classnames for an element (refers to a class in a style sheet) |
* 小结一下:”HTML DOM“ 如下所说的:
In other words: The "HTML DOM" is a standard for how to get, change, add, or delete HTML elements.
vue框架模版语法(Template Syntax)
vue.js API(https://vuejs.org/v2/api/index.html)
W3CSchool HTML DOM手册
W3CSchool HTML Attributes Reference手册
W3CSchool HTML Tags
Koa官方手册
Koa-static
cd ~/Desktop
mkdir node_vue_TemplateSyntax_v-bind_learningload
cd node_vue_TemplateSyntax_v-bind_learningload
npm init
sudo npm install koa koa-static
需要管理员权限,输入密码
在当前路径下创建 index.js 和 index.html 这两个文件,其中 index.js 实现了一个静态web服务器:
index.html
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
<title>ArthurSlogtitle>
head>
<body>
<div id="app">
<button v-bind:disabled="Output">Hello ArthurSlogbutton>
div>
<script>
new Vue({
el: '#app',
data: {
Output: true
}
})
script>
body>
html>
index.js
const serve = require('koa-static');
const Koa = require('koa');
const app = new Koa();
// $ GET /package.json
app.use(serve('.'));
app.listen(3000);
console.log('listening on port 3000');
cd ~/Desktop/node_vue_TemplateSyntax_v-bind_learningload
node index.js
打开浏览器,地址栏输入 127.0.0.1:3000, 回车,正常执行会出来一个button,但是这个button无法接受点击
因为,在 index.html 里我们使用 vue.js模版语法,其中用到了 v-bind:
index.html
<body>
<div id="app">
<button v-bind:disabled="Output">Hello ArthurSlogbutton>
div>
<script>
new Vue({
el: '#app',
data: {
Output: true
}
})
script>
body>
index.html
<button v-bind:disabled="Output">Hello ArthurSlogbutton>
<script>
new Vue({
el: '#app',
data: {
Output: true
}
})
script>
index.html
<button v-bind:disabled="Output">Hello ArthurSlogbutton>
index.html
<script>
new Vue({
el: '#app',
data: {
Output: true
}
})
script>
关键的地方在于,在 HTML 中,elements(元素,指\,\,\ 等等)的 Attribute,具体参考HTML Attribute Reference
现在,把 script 里,”Output” 的值改为 false:
index.html
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js">script>
<title>ArthurSlogtitle>
head>
<body>
<div id="app">
<button v-bind:disabled="Output">Hello ArthurSlogbutton>
div>
<script>
new Vue({
el: '#app',
data: {
Output: false
}
})
script>
body>
html>
cd ~/Desktop/node_vue_TemplateSyntax_v-bind_learningload
node index.js
打开浏览器,地址栏输入 127.0.0.1:3000, 回车,正常执行会出来一个button,但是这个button已经可以接受点击了
至此,我们了解了 vue框架 的模版语法中 v-bind 指令的使用,v-bind的其他用法参考 vue官方API文档。