EddieLiu
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# Vue官網範例練習-新手村上路 本篇透過官網實例了解Vue的基礎操作及概念,以此做個練習紀錄。 ## 01 - Hello Vue 第一課資料綁定插入 string,利用 Mustache 的語法: ``` <div id="app" class="text"> <p>{{message}}</p> <ul> <li>{{ message }}</li> <li>{{FirstName}}</li> <li>{{LastName}}</li> <li>{{FirstName+LastName}}</li> </ul> </div> ``` ``` new Vue({ el: '#app', data: { message: 'Hello Vue.js!', FirstName: 'Eddie', LastName: 'Liu' } }) ``` 結果: ![](https://i.imgur.com/iMDL0ki.png) 附上[程式碼範例](https://jsfiddle.net/EddieLiu58/01hzuq5t/31/) ## 02 - Bind Message Vue 可透過 v-bind 綁定 HTML 的屬性。 ``` <div id="app-2"> <span v-bind:title="message"> 把滑鼠放在這段文字上! </span> </div> ``` ``` var app2 = new Vue({ el: '#app-2', data: { message: '現在時間' + new Date().toLocaleString() } }) ``` 結果: ![](https://i.imgur.com/me1CLX3.png) 附上[程式碼範例](https://jsfiddle.net/EddieLiu58/kjsvhndy/) ## 03 - Conditional Rendering 透過 v-if 這個指令(directive)決定是否顯示p tag。 單純這樣有點無趣,先加入後面會介紹的v-on來綁定button,透過點擊可以改變seen的狀態。 ``` <div id="app-3"> <p v-if="seen">你有看到我嗎?</p> <button type="button" v-on:click="seen=!seen">點我!</button> </div> ``` ``` var app3 = new Vue({ el: '#app-3', data: { seen: true } }) ``` 結果: 未點button,此時seen預設為true,**v-if成立**,文字顯示。 ![](https://i.imgur.com/eppDdZg.png) 點擊button後,因為seen變為false,**v-if並未成立**,綁定v-if的文字則消失了。 ![](https://i.imgur.com/1hP7iL4.png) 附上[程式碼範例](https://jsfiddle.net/EddieLiu58/bt2m5fh4/) ## 04 - List Rendering 透過 v-for 這個指令(directive)顯示 todos list。 ``` <div id="app-4"> <ol> <li v-for="todo in todos"> {{ todo.text }} </li> </ol> <p v-for="(todo, key) in todos"> {{key +1}}.{{todo.text}} </p> </div> ``` ``` var app4 = new Vue({ el: '#app-4', data: { todos: [{ text: '每天練習Vue' }, { text: '每天練習Js' }, { text: '培養美感' } ] } }) ``` 結果: ![](https://i.imgur.com/6vxIgKC.png) 附上[程式碼範例](https://jsfiddle.net/EddieLiu58/2mhr87do/) ## 05 - Event Handling 透過 v-on 綁定 click 事件,點擊button時執行reverseMessage,將message反轉。 ``` <div id="app-5"> <p>{{ message }}</p> <button v-on:click="reverseMessage">Reverse Message</button> </div> ``` ``` var app5 = new Vue({ el: '#app-5', data: { message: '文字會反轉哦!' }, methods: { reverseMessage: function() { this.message = this.message.split('').reverse().join('') } } }) ``` 結果: ![](https://i.imgur.com/r6ga0nh.png) 附上[程式碼範例](https://jsfiddle.net/EddieLiu58/ymuc9Lgn/) ## 06 - Form Input Bindings 透過 v-model 可雙向綁定 input 和 vue instance 的 message。 ``` <div id="app-6"> <p>{{ message }}</p> <input v-model="message"> </div> ``` ``` var app6 = new Vue({ el: '#app-6', data: { message: '請修改文字!' } }) ``` 結果: ![](https://i.imgur.com/GpJEjNi.png) 附上[程式碼範例](https://jsfiddle.net/EddieLiu58/uvkLqzp8/) ## 07 - Component ``` <div id="app-7"> <ol> <todo-item v-for="item in groceryList" v-bind:todo="item" v-bind:key="item.id"> </todo-item> </ol> </div> ``` ``` Vue.component('todo-item', { props: ['todo'], template: '<li>{{ todo.text }}</li>' }) var app7 = new Vue({ el: '#app-7', data: { groceryList: [{ id: 0, text: 'Vegetables' }, { id: 1, text: 'Cheese' }, { id: 2, text: 'Whatever else humans are supposed to eat' } ] } }) ``` 結果: ![](https://i.imgur.com/XGCgWQy.png) 附上[程式碼範例](https://jsfiddle.net/EddieLiu58/wk4r7x5u/#&togetherjs=EMFcTyDTT3)

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully