Skip to content

Instantly share code, notes, and snippets.

@milkmidi
Last active November 28, 2019 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milkmidi/c9fcc1450d1779bfac0467b41d517016 to your computer and use it in GitHub Desktop.
Save milkmidi/c9fcc1450d1779bfac0467b41d517016 to your computer and use it in GitHub Desktop.
DebugComponent.js
/**
* 本機開發用,點了可以直接開 vscode
*/
interface Props {
path: string
}
export default {
name: 'DebugComponent',
functional: true,
props: {
path: {
type: String,
required: true,
},
},
render(createElement, { props }) {
if (process.env.NODE_ENV !== 'development') {
alert('👿 Development mode only');
return null;
}
const { path }:Props = props;
const click = () => fetch(`/__open-in-editor?file=${path}`);
const fileName:string = path.split('/').pop();
return createElement('div',
{
class: '🤜😝🤛',
style: {
cursor: 'pointer',
background: '#c0392b',
padding: '10px',
borderRadius: '10px',
color: 'white',
fontSize: '24px',
},
on: { click },
},
[fileName]);
},
};
<script>
export default {
name: 'Rockroll',
mounted() {
console.log('hi rockroll');
},
};
</script>
<template lang="pug">
.rockroll
if DEV_MODE
DebugComponent(path="components/Rockroll.vue")
h1 Rockroll 🤘
</template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment