talquei
1.0.0
忘記那些無聊和不直覺的形式。使用 talquei,您可以快速建立如上圖所示的奇妙形式。
使用套件管理器安裝:
$ yarn add talquei
添加到您的應用程式中:
import Vue from 'vue'
import Talquei from 'talquei'
// import the styles
import 'talquei/dist/talquei.min.css'
Vue . use ( Talquei )
或匯入到您的元件中:
import { Talquei , TalqueiMessage } from 'talquei'
export default {
components : {
Talquei ,
TalqueiMessage
}
}
Talquei
元件應該包裝任何TalqueiMessage
:
< template >
< Talquei >
< TalqueiMessage text = " Hi! My name is Talquei! " />
< TalqueiMessage text = " I'm a plugin to help you. " />
</ Talquei >
</ template >
您可以透過 prop 或 slot 請求使用者輸入。該道具基本上會將您的標籤注入表單中並填充v-model
中的條目。
< template >
< Talquei >
< TalqueiMessage text = " What's your name? " />
< TalqueiMessage
v-model = " name "
: input = " { tag : ' text ' , placeholder : ' Enter your name ' } "
is-user
/>
</ Talquei >
</ template >
< script >
export default {
data : () => ({
name : ' '
})
}
</ script >
當使用者輸入文字時,您可以使用 prop template
對其進行格式化:
< template >
< Talquei >
< TalqueiMessage
: input = " { tag : ' text ' , placeholder : ' Enter your name ' } "
template = " My name is {text} "
is-user
/>
</ Talquei >
</ template >
如果您需要預先定義的答案(例如select
或radio
標籤),您可以設定input.type = 'select'
並在options
欄位中傳遞您的物件:
< template >
< Talquei >
< TalqueiMessage text = " Which front-end framework do you prefer? " />
< TalqueiMessage
v-model = " name "
: input = " { tag : ' select ' , options : frameworks } "
is-user
/>
</ Talquei >
</ template >
< script >
export default {
data : () => ({
frameworks : {
vue : ' Vue.js ' ,
angular : ' AngularJS ' ,
ember : ' Ember.js '
}
})
}
</ script >
當您希望v-if
屬性顯示條件訊息時使用:
< template >
< Talquei >
< TalqueiMessage text = " Which front-end framework do you prefer? " />
< TalqueiMessage
v-model = " name "
: input = " { tag : ' select ' , options : frameworks } "
is-user
/>
< TalqueiMessage text = " What plugins do you usually use in your projects? " />
< TalqueiMessage
v-if = " answer === ' vue ' "
v-model = " plugin "
: input = " { tag : ' text ' , placeholder : ' talquei ' } "
is-user
/>
</ Talquei >
</ template >
</ script >
如果您需要建立更複雜的輸入(如驗證、自訂元件),您可以使用插槽。完成後,請記住從Talquei
元件呼叫next()
方法。
< template >
< Talquei ref = " talquei " >
< TalqueiMessage text = " Hello " >
< form @ submit . stop = " onSubmit " >
< input ref = " input " type = " text " >
< button >Ok</ button >
</ form >
</ TalqueiMessage >
</ Talquei >
</ template >
< script >
export default {
methods : {
onSubmit () {
this . name = this . $refs . input . value
this . $refs . talquei . next ()
}
}
}
</ script >
Talquei
組件姓名 | 描述 | 類型 | 預設 |
---|---|---|---|
autoRun | 安裝後開始對話 | Boolean | true |
姓名 | 描述 |
---|---|
default | 在此插入您的TalqueiMessage 。不需要根元素 |
init(): void
如果將autoRun
設為false
請使用此方法啟動對話。
next(): void
搜尋下一則訊息。嵌套訊息將注入此方法以在完成輸入時呼叫。
TalqueiMessage
元件姓名 | 描述 | 類型 | 預設 |
---|---|---|---|
input | 請求用戶輸入 查看詳細信息 | Object | undefined |
isUser | 定義為使用者編寫的訊息 | Boolean | false |
text | 要顯示的文本,如果isUser 將不會被鍵入 | String | undefined |
value | 僅適用於v-model | String | undefined |
template | 格式化使用者輸入 | String | {text} |
input
對象將根據通知的tag
建立基本表單,如果您喜歡使用插槽,則不應定義。
tag
:有效標籤目前為text
或select
。options
( select
):使用此欄位定義具有可用選項的object
。placeholder
( text
):設定輸入欄位的佔位符。type
( text
):設定輸入欄位的類型。預設為text
。 姓名 | 描述 |
---|---|
default | 如果您需要更複雜或個人化的使用者輸入,請使用此選項 |
avatar | 更改用作頭像的元素。預設為“?” |
如果您想為此專案做出貢獻,請參閱我們的貢獻指南。