1

I am working on my personal website, and I would like to display an expanded form of my cover letter in the middle of the page. Is there a way to import the contexts of a .txt file into a Vue component? The contents is static, so I would like for it to occur at compile time so that it is wrapped in a <p> or <div> tag in the HTML.

2

1 Answer 1

3

I was able able to get the text imported by using the contents of the link shared in the comments here.

What I did was install the raw-loader webpack package from NPM, then in my component, I import the text as a string, split the string by double newlines, and pass that in the data property function. In the template, I was able to iterate over the array I created with the split(), and generate <span>'s for each paragraph.

<template>
  <div id="app">
    <p>
      <span class="pg" v-for="paragraph in letter" :key="paragraph">
          {{paragraph}}
      </span>
    </p>
  </div>
</template>

<script>
import Letter from 'raw-loader!./assets/letter.txt'

export default {
  name: 'App',
  data: function () {
      return {
          letter: Letter.split("\n\n")
      }
  },
  components: {
  }
}
</script>

<style>
#app {
.pg {
    display: block;
}
</style>
Sign up to request clarification or add additional context in comments.

2 Comments

I tried that but get message: This dependency was not found: * raw-loader!./assets/test.txt
@bartburkhardt check the anwser again. "What I did was install the raw-loader webpack package from NPM"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.