0

I actually was trying to install vuex-project and implement the code from https://www.nativescript.org/blog/data-management-with-sqlite-and-vuex-in-a-nativescript-vue-app except I only got /app instead of /src... Anyway, I got the following error

TypeError: cannot assign to read only property of object '#<Object>'

in main.js

import Vue from 'nativescript-vue'
import Vuex from 'vuex'
import App from './components/App'
import VueDevtools from 'nativescript-vue-devtools'

if(TNS_ENV !== 'production') {
  Vue.use(VueDevtools)
}
// Prints Vue logs when --env.production is *NOT* set while building
Vue.config.silent = (TNS_ENV === 'production')

const Sqlite = require("nativescript-sqlite");

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        database: null,
        data: []
    },
    mutations: {
      init(state, data) {
        state.database = data.database;
      },
      load(state, data) {
        state.data = [];
        for(var i = 0; i < data.data.length; i++) {
            state.data.push({
                firstname: data.data[i][0],
                lastname: data.data[i][1]
            });
        }
      },
      save(state, data) {
        state.data.push({
            firstname: data.data.firstname,
            lastname: data.data.lastname
        });
      },
     },
    actions: {
      init(context) {
        (new Sqlite("my.db")).then(db => {
            db.execSQL("CREATE TABLE IF NOT EXISTS people (id INTEGER     PRIMARY KEY AUTOINCREMENT, firstname TEXT, lastname TEXT)").then(id => {
            context.commit("init", { database: db });
        }, error => {
            console.log("CREATE TABLE ERROR", error);
        });
    }, error => {
        console.log("OPEN DB ERROR", error);
    });
},
insert(context, data) {
    context.state.database.execSQL("INSERT INTO people (firstname, lastname) VALUES (?, ?)", [data.firstname, data.lastname]).then(id => {
        context.commit("save", { data: data });
    }, error => {
        console.log("INSERT ERROR", error);
    });
},
query(context) {
    context.state.database.all("SELECT firstname, lastname FROM people", []).then(result => {
        context.commit("load", { data: result });
    }, error => {
        console.log("SELECT ERROR", error);
    });
}
 }
});

Vue.prototype.$store = store;

module.exports = store;

So in the last line, I used exports...what am I missing?


Getting only a repeating files from directory and subdirectories

I'm trying to do script for finding non-unique files.

The script should take one .csv file with data: name of files, LastWriteTime and Length. Then I try to make another .csv based on that one, which will contain only those objects whose combination of Name+Length+LastWriteTime is NON-unique.

I tried following script which uses $csvfile containing files list:

$csvdata = Import-Csv -Path $csvfile -Delimiter '|'
$csvdata |
    Group-Object -Property Name, LastWriteTime, Length |
    Where-Object -FilterScript { $_.Count -gt 1 } |
    Select-Object -ExpandProperty Group -Unique |
    Export-Csv $csvfile2 -Delimiter '|' -NoTypeInformation -Encoding Unicode

$csvfile was created by:

{
    Get-ChildItem -Path $mainFolderPath -Recurse  -File |
        Sort-Object $sortMode |
        Select-Object Name, LastWriteTime, Length, Directory |
        Export-Csv $csvfile -Delimiter '|' -NoTypeInformation -Encoding Unicode
}

(Get-Content $csvfile) |
    ForEach-Object { $_ -replace '"' } |
    Out-File $csvfile -Encoding Unicode

But somehow in another $csvfile2 there is only the one (first) non-unique record. Does anyone have an idea how to improve it so it can list all non-unique records?

4

1 回答 1

0

You don't really need module.exports = store; when you have declared everything within the main.js file, at least it doesn't add any value to your application / code.

This issue seems to be open issue with webpack, checkout the Github issue for more details.

于 2019-01-20T16:33:57.553 回答