Evaluate and test Vue scripts using single HTML file

How do you test your Vue code blocks and theories?

Of course, you can simply have a test Vue project and throw in a single file component each time. Or, you could follow a simple structure to create a HTML/JS files.

Or, you could just create everything in a single HTML page and clone it for quick tests. Not a new concept by any means - but I still wonder why I stick to SFCs each and every time.

Code below -

<!DOCTYPE html>
    <title>Test. Test. Test</title>
    <script src="https://unpkg.com/vue"></script>
    <div id="app" class="panel">
      <p class="panel-heading has-text-centered is-top-8">
        Test String Manipulations
      <div class="panel-block columns has-text-centered">
        <div class="column">
            placeholder="Enter some text.."
            class="is-primary is-size-4"
      <div class="panel-block has-text-centered">
        <p class="column">Length: {{ testStr.length }}</p>
      <div class="panel-block has-text-centered">
        <p class="column">Reverse: {{ reverseTest }}</p>

    <script type="text/javascript">
      var app = new Vue({
        el: "#app",
        data: {
          testStr: ""
        computed: {
          reverseTest() {
            return this.testStr
              ? this.testStr
              : "...";

See the above code in action - vue-test-single-html-file

So, if we can do all this within a single HTML file - why use SFCs for testing at all?

Well, SFCs are particularly useful when you are testing a whole bunch of stuff - e.g. Vuetify + that new sweet alert, test how the newest charting library looks like in Quasar, using abstraction when dealing with GraphQL, or just test Vuex modules across SFCs!

comments powered by Disqus