vue 多行输入框显示行号

一、概述

因业务需求,多行文本需要显示行号,方便查看配置。

由于默认的textarea输入框无法显示行号,因此需要使用第三方插件才行。

 

二、插件

我找了一个插件,叫bin-code-editor,它原本是用来输入json数据的,也可以做json格式校验。

但是java项目的配置文件,也不一定是json格式的,而是yaml格式的。因此,只需要去掉json校验即可。

 

安装模块

npm install bin-code-editor -d

 

引入

在 main.js 中写入2行

import CodeEditor from 'bin-code-editor';
Vue.use(CodeEditor);

 

test.vue

<template>
  <div>
    <div>
      <b-code-editor v-model="prodDesc" :auto-format="false" :smart-indent="true" theme="idea" :indent-unit="4"
                     :line-wrap="false" :lint="false" ref="editor"></b-code-editor>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        prodDesc: 'SQL.url=jdbc:sqlserver://127.0.0.1; DatabaseName=BaseFrame\n' +
          'SQL.userName=sa\n' +
          'SQL.passWord=-+'
      }
    },
    mounted() {
    },
    methods: {}
  }
</script>
<style type="text/css">
</style>
View Code

 

访问测试页面,效果如下:

 

posted @ 2022-08-17 17:21  肖祥  阅读(564)  评论(0编辑  收藏  举报