Miya Jian
    • 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 表單驗證套件: vee-validate (ver. 2) ## 安裝 ``` npm install vee-validate --save ``` 再於 main.js (Vue cli 中的 Vue 注入點),將這個套件匯入專案中: ``` @import VeeValidate* from 'vee-validate' //因為是在node module 中的套件,所以只需要套件名稱就可以了 Vue.use(VeeValidate); //名稱對應到上述 *,也就是我們為匯入的套件賦予的名稱 ``` ## 使用到 input * 這個套件是以 input 標籤裡的 name 屬性裡的值做對應; 並使用 v-validate 這個指令即可。 有這個 name 的值,vee-validate 才知道要去哪個 input 做驗證。 ``` <input name="email"> ``` ``` <span v-if="errors.has('email')"></span> ``` - errors.has('email'): - 判斷含 name="email" 這個 input 是否有錯誤。 - 回傳 true / false。有錯誤回傳 true,否則 false。 ### 針對常見表單輸入的回饋 - errors.first('email') 驗證 email 時,回傳相關的驗證錯誤訊息。 這部分有點像是針對`errors` 給我們的更詳細的查閱。 ### vee-validate 的運作方式 vee-validate 透過 `v-validate` 和 `name` 做表單元素的分組和驗證;然後再由 `error` 這個物件告知使用者每一個綁定 v-validate 的 input 於驗證後產生的相關訊息。errors.has() 讓我們查閱 vee-validate 驗證後錯誤的 input 有哪些。例如, `errors.has('email')` 就是在查閱這個驗證錯誤的表單有沒有包含 email 這一項。 由這樣的使用方式可以得知,vee-validate 的 errors 運作方式有點像是 JS 的事件綁定。我們在事件綁定中,在 event handler 裡代入一個 `e 或 event` 的參數,就可以查閱這個事件被觸發時的各種相關訊息。 這邊也是相當類似的。透過 errors 這個物件,我們也可以查閱 vee-validate 在做過驗證之後,產生和驗證錯誤的表單的相關訊息。 **而,`errors.first('')` 則是這個套件提供給我們使用的客戶端回饋訊息。(也就是在表單驗證錯誤時,給使用者看的訊息)** 是給使用者的回饋訊息,以 Vue 的 `{{ }}` 方法顯示到網頁上。 ``` <input name='email' v-validate="'required'"> <span v-if="error.has('email')">{{ errors.first('email') }}</span> ``` 以 email 為例,使用`first()` 這個方法,vee-validate 就會針對 email 做驗證。除了一般的告知使用者 email 為必填,也可以回饋詳細的錯誤訊息,例如,email 的格式不對等等。 **PS. 在 errors 中代入的參數都是 input 中 name 標籤裡的值,這部分要特別注意。** ## vee-validate 小結 1. input 需要有 name 做為表單的驗證依據,name、email、tel 等等。 3. v-validate ="'required'" (字串裡面有字串) 標記為需要驗證的表單內容 4. errors.has('...') 驗證這個表單是否錯誤,錯誤回傳 true 5. errors.first('...') 為套件給我們的回饋訊息,以 `{{ }}` 的方式渲染給使用者看 ## requried 屬性 在上述我們只是做好表單的驗證功能,但是並不會阻止瀏覽器送出表單。input 只認得 HTML 標籤的 required 屬性: ``` <input...required> ``` 如果要做到 submit 之前,做好套件的驗證,再交由瀏覽器提出表單,就需要從 method 做處理,讓表單驗證成功之後,再向遠端資料庫送出表單內容。這時候就不需要使用 required 標籤,就可以讓顧客再填寫必須欄位後,再送出表單了。 ``` this.$validator.validate().then(valid => { // 提交表單的 ajax 行為 }); ```

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