Skip to main content

Understanding Vue

In trying to debug the latest problem with vue-router (can't add a new page /person), I want to back up and understand vue fundamentals better.

vue executable

Vue (3.9.2) is installed on my Windows system, so that I can say vue create <app-name> in any directory. vue info shows that I have npm (6.4.1) in C:\Program Files\nodejs\npm.CMD, but that @vue/cli is not installed.

c:\Users\alast\AppData\Roaming\npm\vue.cmd - is basically node vue.js.

vue create makes a scaffold:

<project>/
    public/
        index.html
        favicon.html
    src/        <-- '@' in an import refers to here
        assets/
        components/
        views/
        App.vue
        main.js  <-- entry point
        router.js

vue ui runs the browser-based control app (at localhost:8000).

Modules

Vue seems to make extensive use of JavaScript "modules" for its component system. In JavaScript, the export statement makes an object (or resource in general) available. You say this in firstfile.js:

export { name: "App", data: "1234" }

Whatever other code is going on in firstfile.js, you are offering that object to the world as the entry point. Another file (which could be a module) can bring it in with an import statement:

import App from './firstfile'

If you want to be able to say import defaultExport from "./firstfile" you need the default keyword:

export default { name: "MyMod", data: "1234" }

Apparently, every .vue file is a module.

In PHP, the include statement is replaced by the contents of the file, so it is executed right there. Import may work the same way (I don't know), but since it's typically an object literal, it doesn't get executed. It brings it into the namespace of the importing file. They say you are importing "bindings" only--that is, the ability to refer to the object and its constituents by name.

Vue Files

Vue Files have three parts: Template, Script, and Style. I think it works like this: Vue compiles the template, replacing vue commands and mustache injections with real references and puts the result into the export object. So, the export object has name:, data: and now html: components. I don't know specifically, but I think only the Script portion is run when the .vue file is imported by its parent.

Again, bindings. Importing a .vue file gives you access to its data, computed, methods, and its processed template and style. If you use it in a template context, its html gets inserted in place.


Comments

Popular posts from this blog

A JSON Db Product?

The last post "solved" the problem of many-to-many table joins by papering over the association table with a RESTful JSON interface. As long as we're using JSON, we might as well take advantage of multi-valued table cells. I'm naturally wondering where this leads. JSON identifiers and types and SQL identifiers and types overlap so much that their intersection is a useful subset. Camel-case fields in string, number, bool flavors. Many-to-many occurs often in the world: Students in Classes Actors in Films (musicians on recorded songs) Parts in Assemblies Customers and Products (joined by Orders) The generalized description is that a Table requires a unique identifier for each row. Tables list students, actors, films, customers, and so on.  An Association Table is has two or more foreign keys that match unique identifiers in other tables. The knowledge of how a FK maps to a specific Table is baked in--we wouldn't want a "table name" column....

JSON/MySQL Schemas

As noted previously, there is a lot of overlap between the RDBMS world and the JSON world. Identifiers JSON is defined to allow identifiers of any kind of Unicode string, encoded in UTF-8 (or UTF-16, etc.). They begin and end with double quotation marks (U+0022), so included quotation marks and '\' must be escaped as \" or \\. Control characters (ASCII 0-x1F) must be escaped as well. In practice, JSON identifiers conform to ECMAScript standards . There are some 68  reserved keywords (function, import, for, if, else, and so on) that should not be used as identifiers. Unexpected reserved words include abstract, await, debugger, delete, finally, instanceof, super, synchronized, transient, volatile, and yield. The spec makes a distinction between identifiers and IdentifierNames (specifically, array keys), but why risk it? ECMAScript allows '$' and '_' anywhere in an identifier. Length or camelCasing are not part of the spec. As for length, there seems t...