To ask you a quick question, the array rendering page

render the page according to the one-dimensional array

Apr.19,2021

define instructions

 // common.js 

export const join = {

  bind (el, binding, vnode) {
    let value = binding.value
    if (Object.prototype.toString.call([]) !== Object.prototype.toString.call(value)) {
      throw new Error('')
    }
    value.forEach((item, index) => {
        // -
      if (index + 1 === value.length) {
        el.innerHTML += `<a href="${item.url || 'javascript:void(0)'}">${item.name}</a>`
      } else {
        el.innerHTML += `<a href="${item.url || 'javascript:void(0)'}">${item.name} - </a>`
      }
    })
  }
}

introduce use

// xxx.vue

<template>
      <div v-join="joinData"></div>
</template>
<script>
import { join } from "@/directives/common";
export default {
  name: "app",
  directives: {
    join
  },
  data(){
    return{
     // 
     joinData: [
        { name: "a", url: "http://www.baidu.com" },
        { name: "b", url: "http://www.jd.com" },
        { name: "c", url: "" } // 
     ]
    }
  }
}
</script>

this way feels reusable. I don't know if you can use this data format.


this effect?

<div>
  <a v-for="item in arr" 
     :key="item"
     :href="item">
    {{ item }} -
  </a>
</div>

<a v-for:"item in arr" :key="item.index" :bind></a> 

like this?


not just one layer v-for

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b39385-2b9cb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b39385-2b9cb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?