Skip to content

Commit e3e436f

Browse files
committed
add some Global funtions
1 parent 6389774 commit e3e436f

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

extra.go

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ type TConfig struct {
2121
KeyCodes map[string]int `js:"keyCodes"`
2222
}
2323

24-
// Vue.partial( id, [definition] )
25-
// id String
26-
// definition String | Node optional
27-
// Register or retrieve a global partial.
28-
// The definition can be a template string, a querySelector that starts with #,
29-
// a DOM element (whose innerHTML will be used as the template string),
30-
// or a DocumentFragment.
31-
func Partial(name, definition string) {
32-
vue.Call("partial", name, definition)
24+
// Vue.extend( options )
25+
// Arguments:
26+
// {Object} options
27+
// Usage:
28+
// Create a “subclass” of the base Vue constructor. The argument should be an object containing component options.
29+
// The special case to note here is the data option - it must be a function when used with Vue.extend().
30+
func Extend(o *Option) *Component {
31+
vm := vue.Call("extend", o.prepare())
32+
return &Component{
33+
&ViewModel{
34+
Object: vm,
35+
},
36+
}
3337
}
3438

3539
// Defer the callback to be executed after the next DOM update cycle.
@@ -71,8 +75,43 @@ func Delete(obj, key interface{}) {
7175
vue.Call("delete", obj, key)
7276
}
7377

74-
var Config = &TConfig{}
78+
// Vue.use( mixin )
79+
//
80+
// Arguments:
81+
//
82+
// {Object | Function} plugin
83+
// Usage:
84+
//
85+
// Install a Vue.js plugin. If the plugin is an Object, it must expose an install method. If it is a function itself, it will be treated as the install method. The install method will be called with Vue as the argument.
86+
// When this method is called on the same plugin multiple times, the plugin will be installed only once.
87+
func Use(plugin interface{}) {
88+
vue.Call("use", plugin)
89+
}
90+
91+
// Vue.mixin( mixin )
92+
//
93+
// Arguments:
94+
//
95+
// {Object} mixin
96+
// Usage:
97+
//
98+
// Apply a mixin globally, which affects every Vue instance created afterwards. This can be used by plugin authors to inject custom behavior into components. Not recommended in application code.
99+
func Mixin(mixin interface{}) {
100+
vue.Call("mixin", mixin)
101+
}
102+
103+
// Vue.compile( template )
104+
//
105+
// Arguments:
106+
//
107+
// {string} template
108+
// Usage:
109+
//
110+
// Compiles a template string into a render function. Only available in the standalone build.
111+
func Compile(template string) (renderFn *js.Object) {
112+
return vue.Call("compile", template).Get("render")
113+
}
75114

76-
func init() {
77-
Config.Object = vue.Get("config")
115+
var Config = &TConfig{
116+
Object: js.Global.Get("Object").New(),
78117
}

0 commit comments

Comments
 (0)