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

Commit

Permalink
docs: add Vue browser example (#2302)
Browse files Browse the repository at this point in the history
* Adds Vue browser example

* Removes pify; uses IPFS.create
  • Loading branch information
dbachko authored and Alan Shaw committed Jul 26, 2019
1 parent 6936465 commit 3fce692
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 0 deletions.
1 change: 1 addition & 0 deletions 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 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 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 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 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 browser-vue/public/favicon.ico
Binary file not shown.
20 changes: 20 additions & 0 deletions 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 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>
Binary file added browser-vue/src/assets/ipfs-vue-screenshot.png
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 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 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 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 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 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),
}

0 comments on commit 3fce692

Please sign in to comment.