question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use with .vue files

See original GitHub issue

Hello!

I’m having problems using this with .vue files, is there a way you know of to work around this? What seems to be happening is that vue-loader replaces the render function set by insertRenderer.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ktsncommented, Mar 19, 2017

Well, you seems to be misunderstanding how vue-loader and HoC work. vue-loader injects compiled template into exported object. If you want to use template in the .vue file, you should export the original object (in your example, you should export Component rather than connected object). So, you need to separate the original component and the wrapped component in different files.

<!-- MyComponent.vue -->
<template>
  <div>
    Hello {{name}}!
  </div>
</template>

<script>
export default {
  name: 'my-component',
  props: ['name'],
  created () {
    alert(`[created]: ${this.name}`)
  }
}
</script>
// MyConnectedComponent.js
import { connect } from 'vuex-connect'
import MyComponent from './MyComponent.vue'

export default connect({
  stateToProps: {
    name: state => state.name
  }
})('my-connected-component', MyComponent)

BTW, I think HoC should not be declared in .vue file because it should just connect store and component.

1reaction
linde12commented, Mar 19, 2017

No, i’m not misunderstanding, i just explained how it worked? 😕

That’s exactly what i’m saying; why should you have to create two files to make one connected component? Look at React where you have “container components” that do both things in one file.

I just think that developers shouldn’t have to adjust their javascript code because they’re in a .vue file. Using higher order functions should always work imo.

Having to use two separate files for our “smart” components is off-putting, because it’s extra and unnecessary work.

Anyway, if it’s not going to be supported i think it should at least be noted that it won’t work in .vue files and that you should have to use two separate files or render functions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Single-File Components - Vue.js
Author modularized components using familiar HTML, CSS and JavaScript syntax; Colocation of inherently coupled concerns; Pre-compiled templates without runtime ...
Read more >
Getting started with Vue - Learn web development | MDN
Using Single File Components, Vue lets you group your templates, corresponding script, and CSS all together in a single file ending in .vue...
Read more >
How to create a Vue.js app using Single-File Components ...
The most basic Vue project will include an HTML, JavaScript, and a Vue file (the file ending in .vue). We will place these...
Read more >
Vue JavaScript Tutorial in Visual Studio Code
To install and use the Vue CLI as well as run the Vue application server, ... see a notification recommending the Vetur extension...
Read more >
Going from plain Vue to .vue files - DEV Community ‍ ‍
But snoop through some popular Vue projects on GitHub, and you'll find that a lot of them don't organize their components in .js...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found