├── .browserslistrc ├── .editorconfig ├── .eslintrc.js ├── .gitignore ├── .npmignore ├── README.md ├── babel.config.js ├── examples ├── App.vue └── main.js ├── package-lock.json ├── package.json ├── packages ├── index.js └── textarea │ ├── index.js │ └── main.vue ├── postcss.config.js ├── public └── index.html └── vue.config.js /.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not ie <= 8 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*.{js,jsx,ts,tsx,vue}] 4 | charset = utf-8 5 | indent_style = space 6 | indent_size = 2 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | 'extends': [ 7 | 'plugin:vue/essential', 8 | '@vue/standard' 9 | ], 10 | rules: { 11 | 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off', 12 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', 13 | "space-before-function-paren": [0, "always"], 14 | "semi": [0, "always"] 15 | }, 16 | parserOptions: { 17 | parser: 'babel-eslint' 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | lib/ 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw* 22 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | examples/ 4 | packages/ 5 | public/ 6 | vue.config.js 7 | babel.config.js 8 | *.map 9 | *.html 10 | 11 | # local env files 12 | .env.local 13 | .env.*.local 14 | 15 | # Log files 16 | npm-debug.log* 17 | yarn-debug.log* 18 | yarn-error.log* 19 | 20 | # Editor directories and files 21 | .idea 22 | .vscode 23 | *.suo 24 | *.ntvs* 25 | *.njsproj 26 | *.sln 27 | *.sw* 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VueTagTextarea 2 | 3 | > 可插入自定义标签的 textarea 4 | 5 | ## 安装 6 | 7 | ``` bash 8 | $ npm install vue-tag-textarea -S 9 | ``` 10 | ## 使用 11 | 12 | 在 `main.js` 文件中引入插件并注册 13 | 14 | ``` bash 15 | # main.js 16 | import VueTagTextarea from 'vue-tag-textarea' 17 | import 'vue-tag-textarea/lib/vue-tag-textarea.css' 18 | Vue.use(VueTagTextarea) 19 | ``` 20 | 21 | 在项目中用使用 VueTagTextarea 22 | 23 | 24 | ```js 25 | 28 | 37 | ``` 38 | 39 | 注意:标签为 `` 40 | 41 | ## 特点 42 | 1. 可以插入自定义的标签,默认为 `` 43 | 2. 基于自定义标签,可以满足模版文案的需求 44 | 45 | ## 参数 46 | 47 | | 参数 | 说明 | 类型 | 默认值 | 48 | | ------ | ------ | ------ | ------ | 49 | | tag | 自定义标签名 | String | wise | 50 | | tools | 配置工具栏 | Array | [{ type: 'link', text: '添加超链接' }, { type: 'tag', text: '添加模版标签' }] | 51 | | maxlength | 最大字符长度 | String, Number | - | 52 | 53 | > 自定义 tag 的时候,需要添加该标签的样式 54 | 55 | 56 | ## 事件 57 | 58 | | 事件名称 | 说明 | 回调参数 | 59 | | ------ | ------ | ------ | 60 | | add | 点击工具栏上的“添加xx”按钮时触发 | type | 61 | 62 | ## Add 事件详解 63 | 工具栏可以通过 tools 参数进行配置,tools 的元素是一个包含 type 和 text 的对象,其中 text 为工具栏按钮的文字。 64 | 当点击工具栏按钮的时候,触发 add 事件,接收一个 type 参数,该参数为 tools 中定义的 type 属性值。 65 | 具体的交互逻辑需要自行开发,最后需要通过 $refs 调用 VueTagTextarea 内部的 addLink() 或者 addTag() 方法,完成添加标签。 66 | 当调用 addTag() 的时候,需要传入一个 text 参数,值为标签的文本内容。 67 | 当调用 addLink() 的时候,需要传入 url 和 text,其中 url 为超链接地址,text 为超链接文本。 68 | VueTagTextarea 最终返回的值是一个 innerHTML。 69 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /examples/App.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /examples/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import TagTextarea from '../packages/index' 4 | 5 | Vue.use(TagTextarea) 6 | 7 | Vue.config.productionTip = false 8 | 9 | new Vue({ 10 | render: h => h(App) 11 | }).$mount('#app') 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-tag-textarea", 3 | "version": "0.1.0", 4 | "main": "lib/vue-tag-textarea.umd.min.js", 5 | "private": false, 6 | "license": "MIT", 7 | "author": "wisewrong <1005915808@qq.com>", 8 | "scripts": { 9 | "serve": "vue-cli-service serve", 10 | "build": "vue-cli-service build", 11 | "lint": "vue-cli-service lint", 12 | "lib": "vue-cli-service build --target lib --name vue-tag-textarea --dest lib packages/index.js" 13 | }, 14 | "dependencies": { 15 | "vue": "^2.5.17" 16 | }, 17 | "devDependencies": { 18 | "@vue/cli-plugin-babel": "^3.0.4", 19 | "@vue/cli-plugin-eslint": "^3.0.4", 20 | "@vue/cli-service": "^3.0.4", 21 | "@vue/eslint-config-standard": "^4.0.0", 22 | "babel-eslint": "^10.0.1", 23 | "eslint": "^5.8.0", 24 | "eslint-plugin-vue": "^5.0.0-0", 25 | "node-sass": "^4.9.0", 26 | "sass-loader": "^7.0.1", 27 | "vue-template-compiler": "^2.5.17" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/index.js: -------------------------------------------------------------------------------- 1 | import Textarea from './textarea/index' 2 | 3 | const components = [ 4 | Textarea 5 | ] 6 | 7 | const install = function (Vue) { 8 | if (install.installed) return 9 | install.installed = true 10 | components.map(component => { 11 | Vue.component(component.name, component) 12 | }) 13 | } 14 | 15 | if (typeof window !== 'undefined' && window.Vue) { 16 | // window.Vue.use(install) 17 | install(window.Vue) 18 | } 19 | 20 | export default { 21 | install, 22 | Textarea 23 | } 24 | -------------------------------------------------------------------------------- /packages/textarea/index.js: -------------------------------------------------------------------------------- 1 | import Textarea from './main.vue' 2 | 3 | Textarea.install = function (Vue) { 4 | Vue.component(Textarea.name, Textarea) 5 | } 6 | 7 | export default Textarea 8 | -------------------------------------------------------------------------------- /packages/textarea/main.vue: -------------------------------------------------------------------------------- 1 | 27 | 28 | 200 | 201 | 217 | 218 | 298 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {} 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | vue-tag-textarea 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | // 修改 src 为 examples 3 | pages: { 4 | index: { 5 | entry: 'examples/main.js', 6 | template: 'public/index.html', 7 | filename: 'index.html' 8 | } 9 | }, 10 | productionSourceMap: false 11 | } 12 | --------------------------------------------------------------------------------