可复用 & 组合: 自定义指令 v-focus


test: {{msg}}
1. v-focus




2. 固定到距离 右侧200 位置

Scroll down the page

2. Stick me 200px from the right of the page


3. 固定到距离 __测 200 位置 > vm.direction="top" //"left"

Scroll down inside this section ↓

3. I am pinned onto the page at 200px to the {{direction}}.


3.2
3.2 right 50

4. 把距离绑定到一个input组件上

4. Stick me {{ pinPadding + 'px' }} from the {{ direction4 }} of the page


4.2

4.2. Stick me {{ pinPadding + 'px' }}
from the {{ direction4 }}
of the page


5. 对象字面量,能传入更多参数: v-demo="{ color: 'white', text: 'hello!' }"
Look at console: F12

5.2 v-pin5="{background:'purple', color:'black', right:'120px' }"

5.2. Stick me using 字面量


6. 在组件中使用 和非 prop 的 attribute 类似,当在组件中使用时,自定义指令总是会被应用在组件的根节点上。
和 attribute 不同,指令不会通过 v-bind="$attrs" 被传入另一个元素。