1

New-ish to Vue nd extremely new to Vuex. Im trying to import a store to my main page from which all my components branch out, but I keep getting an "unexpected token {" error in the browser console. I read through the documentation, but I cant find anything that would address this issue. I have tried changing every bit of syntax I can, and it doesnt seem to make a difference. The brackets around store in the import appear to be the problem, but when I remove them, i just get a new "unexpected identifier", or an "unexpected string" error. Am I importing it incorrectly? This format works fine on all my components, just not on this new vue instance.

vuex-test.blade.php

@extends('core.core_layouts.core_blank')

@section('browsertitle')
@endsection

@section('top-css')
@endsection

@section('breadcrumb')
@endsection


@section('main')
  <component :is="currentView" v-bind="currentProperties"></component>
@endsection


@section('bottom-js')
<script>

    import { store } from './../stores/store1.js';

    var app = new Vue({
        el:"#app",
        store,
        data: {
        currentView: 'org-list',
        choseOrg: {{ $org }},
    },  // end data
    computed: {
        currentProperties: function() {
            if (this.currentView === 'org-list') { return { } }
            if (this.currentView === 'add-org') { return { parentOrg: '' } }
        }
    },   
    mounted : function() {
    }, // end mounted
    methods: {
    }, // end methods
    components: {
    },
});
</script>
@endsection

store1.js

export const store = new Vuex.Store({
  state: {
    safelyStoredNumber: 'ret',
    count: 2,
  },
  mutations: {
    setOrgIdentity(state, orgID) {
    state.OrgID = orgID
    }
  }
 });
6
  • Where do you get that error? At the browser? Also, can you show the source for store1.js? Commented Mar 23, 2018 at 1:49
  • sorry, the question wasn't as complete as it should have been. I have updated it with store1.js nd the complete file where it isnt working. Commented Mar 23, 2018 at 14:53
  • And where do you get the error? at the browser? Commented Mar 23, 2018 at 15:16
  • yes, at the browser. Commented Mar 23, 2018 at 15:17
  • import won't work there. Try changing import { store } from './../stores/store1.js'; to something like <script src="./../stores/store1.js"></script> (change the path to what is more appropriate) and in store1.js do: window.store = new Vuex.Store({. Commented Mar 23, 2018 at 15:21

1 Answer 1

1

Per comments:

Yes, I get the error at the browser.

import won't work there. It is meant to run on node.js, during the build phase of a vue-cli-based project.

If you are deploying the code directly to browser, you will need to use code that is supported by the browser. In this case, the solution to import other JavaScript files is standard <script> tags.

So, in your code, change:

import { store } from './../stores/store1.js';

to something like (change the path to what is more appropriate):

<script src="./../stores/store1.js"></script>

And in store1.js (because export is too meant for node.js), replace:

export const store = new Vuex.Store({

With:

window.store = new Vuex.Store({
Sign up to request clarification or add additional context in comments.

Comments

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.