Skip to content

Instantly share code, notes, and snippets.

@temistoclesarea
Last active May 6, 2018 17:57
Show Gist options
  • Save temistoclesarea/d649c406247daeb12199c393b3b6661b to your computer and use it in GitHub Desktop.
Save temistoclesarea/d649c406247daeb12199c393b3b6661b to your computer and use it in GitHub Desktop.
getPositionRand
<template v-for="g in data.Zones">
{{getPositionRand()}} // dessa forma ele chama o getPositionRand()
<a
class="zone"
???getPositionRand()??? // mas não sei chamar o method aqui
:title="'C:'+g.code+' T:'+g.time+' P:'+pos['p']+' H:'+pos['ph']+' W:'+pos['pw']"
:key="g.id"
:style="'width:'+pos['p']+'px;'+'height:'+pos['p']+'px;'+'top:'+pos['ph']+'px;'+'left:'+pos['pw']+'px;'"
:href="'#c:'+g.code"></a>
</template>
methods: {
getPositionRand: function (w = 800, h = 600) {
let pos = []
pos['p'] = Math.floor(Math.random() * 18) + 4
pos['pw'] = Math.floor(Math.random() * (w - pos['p']))
pos['ph'] = Math.floor(Math.random() * (h - pos['p']))
this.pos = pos
}
}
// solução
<a
class="zone"
v-for="g in data.Zones"
v-bind="getPositionRand()"
:title="'C:'+g.code+' T:'+g.time+' P:'+pos['p']+' H:'+pos['ph']+' W:'+pos['pw']"
:key="g.id"
:style="'width:'+pos['p']+'px;'+'height:'+pos['p']+'px;'+'top:'+pos['ph']+'px;'+'left:'+pos['pw']+'px;'"
:href="'#c:'+g.code"></a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment