Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

docs: add Vue browser example #2302

Merged
merged 2 commits into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Clone this repo to explore these tutorials on your local machine:

- [js-ipfs in the browser with Browserify](./browser-browserify)
- [js-ipfs in the browser with Parcel.js](./browser-parceljs)
- [js-ipfs in the browser with Vue](./browser-vue)
- [js-ipfs in the browser with WebPack](./browser-webpack)
- [js-ipfs in the browser with a `<script>` tag](./browser-script-tag)
- [js-ipfs in electron](./run-in-electron)
Expand Down
21 changes: 21 additions & 0 deletions examples/browser-vue/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.DS_Store
/node_modules
/dist

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
41 changes: 41 additions & 0 deletions examples/browser-vue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# IPFS Vue app

A minimal demonstration of how to use `js-ipfs` with `Vue`.

![screenshot of the js ipfs node id info](./src/assets/ipfs-vue-screenshot.png)

This project was bootstrapped with [Vue CLI](https://cli.vuejs.org/).

## Project setup

```bash
npm install
```

### Compiles and hot-reloads for development

```bash
npm run serve
```

### Compiles and minifies for production

```bash
npm run build
```

### Run your tests

```bash
npm run test
```

### Lints and fixes files

```bash
npm run lint
```

### Customize configuration

See [Configuration Reference](https://cli.vuejs.org/config/).
3 changes: 3 additions & 0 deletions examples/browser-vue/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@vue/app'],
};
47 changes: 47 additions & 0 deletions examples/browser-vue/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "browser-vue",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^2.6.5",
"ipfs": "file:../../",
"vue": "^2.6.10"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^3.9.0",
"@vue/cli-plugin-eslint": "^3.9.0",
"@vue/cli-service": "^3.9.0",
"babel-eslint": "^10.0.1",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"vue-template-compiler": "^2.6.10"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"postcss": {
"plugins": {
"autoprefixer": {}
}
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}
Binary file added examples/browser-vue/public/favicon.ico
Binary file not shown.
20 changes: 20 additions & 0 deletions examples/browser-vue/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
<title>IPFS Vue</title>
</head>
<body>
<noscript>
<strong
>We're sorry but browser-vue doesn't work properly without JavaScript enabled. Please enable it to
continue.</strong
>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
32 changes: 32 additions & 0 deletions examples/browser-vue/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<template>
<div id="app">
<ipfs-info />
</div>
</template>

<script>
import IpfsInfo from "./components/IpfsInfo.vue";

export default {
name: "app",
components: {
IpfsInfo
}
};
</script>

<style>
body {
margin: 0;
}
#app {
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
}
</style>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions examples/browser-vue/src/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions examples/browser-vue/src/components/IpfsInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div class="ipfs-info">
<img class="ipfs-logo" alt="IPFS logo" src="../assets/logo.svg" />
<h1>{{ status }}</h1>
<h2>ID: {{ id }}</h2>
<h2>Agent version: {{ agentVersion }}</h2>
</div>
</template>

<script>
export default {
name: "IpfsInfo",
data: function() {
return {
status: "Connecting to IPFS...",
id: "",
agentVersion: ""
};
},
mounted: function() {
this.getIpfsNodeInfo();
},
methods: {
async getIpfsNodeInfo() {
try {
// Await for ipfs node instance.
const ipfs = await this.$ipfs;
// Call ipfs `id` method.
// Returns the identity of the Peer.
const { agentVersion, id } = await ipfs.id();
this.agentVersion = agentVersion;
this.id = id;
// Set successful status text.
this.status = "Connected to IPFS =)";
} catch (err) {
// Set error status text.
this.status = `Error: ${err}`;
}
}
}
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.ipfs-logo {
height: 10rem;
}
</style>
12 changes: 12 additions & 0 deletions examples/browser-vue/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Vue from 'vue';
import App from './App.vue';
import VueIpfs from './plugins/vue-ipfs';

// Load our IPFS plugin.
Vue.use(VueIpfs);

Vue.config.productionTip = false;

new Vue({
render: h => h(App),
}).$mount('#app');
14 changes: 14 additions & 0 deletions examples/browser-vue/src/plugins/vue-ipfs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import IPFS from 'ipfs'

const plugin = {
install(Vue, opts = {}) {
Vue.prototype.$ipfs = IPFS.create(opts)
},
}

// Auto-install
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(plugin)
}

export default plugin
3 changes: 3 additions & 0 deletions examples/browser-vue/vue.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
chainWebpack: config => config.resolve.symlinks(false),
}