'How to save line breaks in database
I'm using typeorm to management my databse with nestjs framework on server and vuejs on client side,
in settings i must provide a large text and i must to save linebreaks (\n
) in database,
my code:
vue textarea
<b-form-textarea
style="white-space: pre-line"
v-model="projectShortDesc"
class="mt-2 description-input"></b-form-textarea>
then i send this data from v-model="projectShortDesc"
to my server,
@Column({
type: 'varchar',
length: 150,
nullable: true
})
shortDescription: string;
and save like this:
project.shortDescription = descFromVue;
await this.conn.getRepository(Project).save(project);
can someone tell me how to save in database '\n' when i enter enter
in description?
thanks for any help!
Solution 1:[1]
To add linebreaks in mysql db ,You need to append /n whenever the user hits on enter key in the text box.I think this will help you
<template>
<div id="app">
<b-form-textarea
style="white-space: pre-line"
v-model="projectShortDesc"
class="mt-2 description-input"
v-on:keyup.enter="onEnter">
</b-form-textarea>
</div>
</template>
<script>
export default {
name: "App",
methods: {
onEnter() {
this.projectShortDesc.apend('/n')
},
},
};
</script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Arun |